Logo Search packages:      
Sourcecode: pulseaudio version File versions

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 65 of file util.c.

                                          {
    const char *p;
    char buf[1024];

#ifdef HAVE_PWD_H
    struct passwd pw, *r;
#endif

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

    if (!(p = (getuid() == 0 ? "root" : NULL)) &&
        !(p = getenv("USER")) &&
        !(p = getenv("LOGNAME")) &&
        !(p = getenv("USERNAME"))) {
#ifdef HAVE_PWD_H

#ifdef HAVE_GETPWUID_R
        if (getpwuid_r(getuid(), &pw, buf, sizeof(buf), &r) != 0 || !r) {
#else
        /* XXX Not thread-safe, but needed on OSes (e.g. FreeBSD 4.X)
            * that do not support getpwuid_r. */
        if ((r = getpwuid(getuid())) == NULL) {
#endif
            pa_snprintf(s, l, "%lu", (unsigned long) getuid());
            return s;
        }

        p = r->pw_name;

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

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

        p = buf;

#else /* HAVE_PWD_H */

        return NULL;
#endif /* HAVE_PWD_H */
    }

    return pa_strlcpy(s, p, l);
}


Generated by  Doxygen 1.6.0   Back to index