openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/systemd/1_242+AUTOINC+db2e367bfc-r0/git/src/basic/unit-name.c
int unit_name_mangle_with_suffix(const char* name, UnitNameMangle flags,
                                 const char* suffix, char** ret)
{
    char* s;
    int r;
    bool mangled;

    assert(name);
    assert(suffix);
    assert(ret);

    if (isempty(name)) /* We cannot mangle empty unit names to become valid,
                          sorry. */
        return -EINVAL;

    if (!unit_suffix_is_valid(suffix))
        return -EINVAL;

    /* Already a fully valid unit name? If so, no mangling is necessary... */
    if (unit_name_is_valid(name, UNIT_NAME_ANY))
        goto good;

    /* Already a fully valid globbing expression? If so, no mangling is
     * necessary either... */
    if ((flags & UNIT_NAME_MANGLE_GLOB) && string_is_glob(name) &&
        in_charset(name, VALID_CHARS_GLOB))
        goto good;

    if (is_device_path(name))
    {
        r = unit_name_from_path(name, ".device", ret);
        if (r >= 0)
            return 1;
        if (r != -EINVAL)
            return r;
    }

    if (path_is_absolute(name))
    {
        r = unit_name_from_path(name, ".mount", ret);
        if (r >= 0)
            return 1;
        if (r != -EINVAL)
            return r;
    }

    s = new (char, strlen(name) * 4 + strlen(suffix) + 1);
    if (!s)
        return -ENOMEM;

    mangled = do_escape_mangle(name, flags & UNIT_NAME_MANGLE_GLOB, s);
    if (mangled)
        log_full(flags & UNIT_NAME_MANGLE_WARN ? LOG_NOTICE : LOG_DEBUG,
                 "Invalid unit name \"%s\" was escaped as \"%s\" (maybe you "
                 "should use systemd-escape?)",
                 name, s);

    /* Append a suffix if it doesn't have any, but only if this is not a glob,
     * so that we can allow "foo.*" as a valid glob. */
    if ((!(flags & UNIT_NAME_MANGLE_GLOB) || !string_is_glob(s)) &&
        unit_name_to_type(s) < 0)
        strcat(s, suffix);

    *ret = s;
    return 1;

good:
    s = strdup(name);
    if (!s)
        return -ENOMEM;

    *ret = s;
    return 0;
}
/**
 *  Convert a string to a unit name. /dev/blah is converted to dev-blah.device,
 *  /blah/blah is converted to blah-blah.mount, anything else is left alone,
 *  except that @suffix is appended if a valid unit suffix is not present.
 *
 *  If @allow_globs, globs characters are preserved. Otherwise, they are
 * escaped.
 */
Convert a string to a unit name. /dev/blah is converted to dev-blah.device,
/blah/blah is converted to blah-blah.mount, anything else is left alone,
except that @suffix is appended if a valid unit suffix is not present.

If @allow_globs, globs characters are preserved. Otherwise, they are
escaped.
Convert a string to a unit name . / dev / blah is converted to dev - blah . device / blah / blah is converted to blah - blah . mount anything else is left alone except that @suffix is appended if a valid unit suffix is not present . If @allow_globs globs characters are preserved . Otherwise they are escaped .
int unit_name_mangle_with_suffix(const char* name, UnitNameMangle flags,
                                 const char* suffix, char** ret)
{
    char* s;
    int r;
    bool mangled;
    assert(name);
    assert(suffix);
    assert(ret);
    if (isempty(name)) 
        return -EINVAL;
    if (!unit_suffix_is_valid(suffix))
        return -EINVAL;
    if (unit_name_is_valid(name, UNIT_NAME_ANY))
        goto good;
    if ((flags & UNIT_NAME_MANGLE_GLOB) && string_is_glob(name) &&
        in_charset(name, VALID_CHARS_GLOB))
        goto good;
    if (is_device_path(name))
    {
        r = unit_name_from_path(name, ".device", ret);
        if (r >= 0)
            return 1;
        if (r != -EINVAL)
            return r;
    }
    if (path_is_absolute(name))
    {
        r = unit_name_from_path(name, ".mount", ret);
        if (r >= 0)
            return 1;
        if (r != -EINVAL)
            return r;
    }
    s = new (char, strlen(name) * 4 + strlen(suffix) + 1);
    if (!s)
        return -ENOMEM;
    mangled = do_escape_mangle(name, flags & UNIT_NAME_MANGLE_GLOB, s);
    if (mangled)
        log_full(flags & UNIT_NAME_MANGLE_WARN ? LOG_NOTICE : LOG_DEBUG,
                 "Invalid unit name \"%s\" was escaped as \"%s\" (maybe you "
                 "should use systemd-escape?)",
                 name, s);
    if ((!(flags & UNIT_NAME_MANGLE_GLOB) || !string_is_glob(s)) &&
        unit_name_to_type(s) < 0)
        strcat(s, suffix);
    *ret = s;
    return 1;
good:
    s = strdup(name);
    if (!s)
        return -ENOMEM;
    *ret = s;
    return 0;
}
int unit_name_mangle_with_suffix ( const char * name , UnitNameMangle flags , const char * suffix , char * * ret ) { char * s ; int r ; bool mangled ; assert ( name ) ; assert ( suffix ) ; assert ( ret ) ; if ( isempty ( name ) ) return - EINVAL ; if ( ! unit_suffix_is_valid ( suffix ) ) return - EINVAL ; if ( unit_name_is_valid ( name , UNIT_NAME_ANY ) ) goto good ; if ( ( flags & UNIT_NAME_MANGLE_GLOB ) && string_is_glob ( name ) && in_charset ( name , VALID_CHARS_GLOB ) ) goto good ; if ( is_device_path ( name ) ) { r = unit_name_from_path ( name , " " , ret ) ; if ( r >= 0 ) return 1 ; if ( r != - EINVAL ) return r ; } if ( path_is_absolute ( name ) ) { r = unit_name_from_path ( name , " " , ret ) ; if ( r >= 0 ) return 1 ; if ( r != - EINVAL ) return r ; } s = new ( char , strlen ( name ) * 4 + strlen ( suffix ) + 1 ) ; if ( ! s ) return - ENOMEM ; mangled = do_escape_mangle ( name , flags & UNIT_NAME_MANGLE_GLOB , s ) ; if ( mangled ) log_full ( flags & UNIT_NAME_MANGLE_WARN ? LOG_NOTICE : LOG_DEBUG , " \" \" \" \" " " " , name , s ) ; if ( ( ! ( flags & UNIT_NAME_MANGLE_GLOB ) || ! string_is_glob ( s ) ) && unit_name_to_type ( s ) < 0 ) strcat ( s , suffix ) ; * ret = s ; return 1 ; good : s = strdup ( name ) ; if ( ! s ) return - ENOMEM ; * ret = s ; return 0 ; }
Convert a string to a unit name.
Convert a string to a unit name .
/* We cannot mangle empty unit names to become valid,
                          sorry. */ /* Already a fully valid unit name? If so, no mangling is necessary... */ /* Already a fully valid globbing expression? If so, no mangling is
     * necessary either... */ /* Append a suffix if it doesn't have any, but only if this is not a glob,
     * so that we can allow "foo.*" as a valid glob. */