static unsigned int decode_uid(const char *s, int *res)
{
    *res = 0;

    if (!s || *s == '\0') {
        *res = -EINVAL;
        return -1;
    }
#ifndef TEST_USER
    unsigned int v;
    if (isalpha(s[0]))
        return android_name_to_id(s, res);

    errno = 0;
    v = (unsigned int)strtoul(s, 0, 0);
    if (errno) {
        *res = -errno;
        return -1U;
    }
    return v;
#else
    /* HACK for testing only */
    return TEST_USER;
#endif
}
Exemple #2
0
/*
 * decode_uid - decodes and returns the given string, which can be either the
 * numeric or name representation, into the integer uid or gid. Returns -1U on
 * error.
 */
unsigned int decode_uid(const char *s)
{
    unsigned int v;

    if (!s || *s == '\0')
        return -1U;
    if (isalpha(s[0]))
        return android_name_to_id(s);

    errno = 0;
    v = (unsigned int) strtoul(s, 0, 0);
    if (errno)
        return -1U;
    return v;
}