Logo Search packages:      
Sourcecode: pulseaudio version File versions

char* pa_get_home_dir ( char *  s,
size_t  l 
)

Return the home directory of the current user

Definition at line 126 of file util.c.

                                         {
    char *e;

#ifdef HAVE_PWD_H
    char buf[1024];
    struct passwd pw, *r;
#endif

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

    if ((e = getenv("HOME")))
        return pa_strlcpy(s, e, l);

    if ((e = getenv("USERPROFILE")))
        return pa_strlcpy(s, e, l);

#ifdef HAVE_PWD_H

    errno = 0;
#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
        if (!errno)
            errno = ENOENT;

        return NULL;
    }

    return pa_strlcpy(s, r->pw_dir, l);
#else /* HAVE_PWD_H */

    errno = ENOENT;
    return NULL;
#endif
}


Generated by  Doxygen 1.6.0   Back to index