Logo Search packages:      
Sourcecode: pulseaudio version File versions  Download package

PA_C_DECL_BEGIN char* pa_get_user_name ( char *  s,
size_t  l 
)

Return the current username in the specified string buffer.

Definition at line 68 of file util.c.

                                          {
    const char *p;
    char *name = NULL;
#ifdef OS_IS_WIN32
    char buf[1024];
#endif

#ifdef HAVE_PWD_H
    struct passwd *r;
#endif

    pa_assert(s);
    pa_assert(l > 0);

    if ((p = (getuid() == 0 ? "root" : NULL)) ||
        (p = getenv("USER")) ||
        (p = getenv("LOGNAME")) ||
        (p = getenv("USERNAME")))
    {
        name = pa_strlcpy(s, p, l);
    } else {
#ifdef HAVE_PWD_H

        if ((r = pa_getpwuid_malloc(getuid())) == NULL) {
            pa_snprintf(s, l, "%lu", (unsigned long) getuid());
            return s;
        }

        name = pa_strlcpy(s, r->pw_name, l);
        pa_getpwuid_free(r);

#elif defined(OS_IS_WIN32) /* HAVE_PWD_H */
        DWORD size = sizeof(buf);

        if (!GetUserName(buf, &size)) {
            errno = ENOENT;
            return NULL;
        }

        name = pa_strlcpy(s, buf, l);

#else /* HAVE_PWD_H */

        return NULL;
#endif /* HAVE_PWD_H */
    }

    return name;
}


Generated by  Doxygen 1.6.0   Back to index