Changeset e7125f4ec9d298e514b56f721ebac2a7be14b24a

Show
Ignore:
Timestamp:
05/05/08 22:34:21 (4 months ago)
Author:
Rémi Denis-Courmont <rem@videolan.org>
git-committer:
Rémi Denis-Courmont <rem@videolan.org> 1210019661 +0300
git-parent:

[04a4af73ffcb9602a697e5b2bd8df21c9e9b3c6d]

git-author:
Rémi Denis-Courmont <rem@videolan.org> 1210016118 +0300
Message:

Use getpwuid_r - thread safety

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • configure.ac

    ra88db78 re7125f4  
    465465 
    466466dnl Check for usual libc functions 
    467 AC_CHECK_FUNCS([gettimeofday strtod strtol strtof strtoll strtoull strsep isatty vasprintf asprintf swab sigrelse getpwuid memalign posix_memalign if_nametoindex atoll getenv putenv setenv gmtime_r ctime_r localtime_r lrintf daemon scandir fork bsearch lstat strlcpy strdup strndup strnlen atof lldiv posix_fadvise posix_madvise]) 
     467AC_CHECK_FUNCS([gettimeofday strtod strtol strtof strtoll strtoull strsep isatty vasprintf asprintf swab sigrelse getpwuid_r memalign posix_memalign if_nametoindex atoll getenv putenv setenv gmtime_r ctime_r localtime_r lrintf daemon scandir fork bsearch lstat strlcpy strdup strndup strnlen atof lldiv posix_fadvise posix_madvise]) 
    468468AC_CHECK_FUNCS(strcasecmp,,[AC_CHECK_FUNCS(stricmp)]) 
    469469AC_CHECK_FUNCS(strncasecmp,,[AC_CHECK_FUNCS(strnicmp)]) 
  • src/config/core.c

    r99fec92 re7125f4  
    4040#endif 
    4141 
    42 #if defined(HAVE_GETPWUID
    43 #   include <pwd.h>                                            /* getpwuid() */ 
     42#if defined(HAVE_GETPWUID_R
     43#   include <pwd.h> 
    4444#endif 
    4545 
     
    618618} 
    619619 
    620 /***************************************************************************** 
    621  * config_GetHomeDir, config_GetUserDir: find the user's home directory. 
    622  ***************************************************************************** 
    623  * This function will try by different ways to find the user's home path. 
    624  * Note that this function is not reentrant, it should be called only once 
    625  * at the beginning of main where the result will be stored for later use. 
    626  *****************************************************************************/ 
    627620static char *GetDir( bool b_appdata ) 
    628621{ 
     
    672665 
    673666#elif defined(UNDER_CE) 
    674  
     667    (void)b_appdata; 
    675668#ifndef CSIDL_APPDATA 
    676669#   define CSIDL_APPDATA 0x1A 
     
    682675    if( SHGetSpecialFolderPath( NULL, whomedir, CSIDL_APPDATA, 1 ) ) 
    683676        return FromWide( whomedir ); 
     677#else 
     678    (void)b_appdata; 
    684679#endif 
    685680 
    686681    psz_localhome = getenv( "HOME" ); 
     682#if defined(HAVE_GETPWUID_R) 
     683    char buf[sysconf (_SC_GETPW_R_SIZE_MAX)]; 
    687684    if( psz_localhome == NULL ) 
    688685    { 
    689 #if defined(HAVE_GETPWUID) 
    690         struct passwd *p_pw; 
    691         (void)b_appdata; 
    692  
    693         if( ( p_pw = getpwuid( getuid() ) ) != NULL ) 
    694             psz_localhome = p_pw->pw_dir; 
    695         else 
    696 #endif 
    697         { 
    698             psz_localhome = getenv( "TMP" ); 
    699             if( psz_localhome == NULL ) 
    700                 psz_localhome = "/tmp"; 
    701         } 
    702     } 
     686        struct passwd pw, *res; 
     687 
     688        if (!getpwuid_r (getuid (), &pw, buf, sizeof (buf), &res) && res) 
     689            psz_localhome = pw.pw_dir; 
     690    } 
     691#endif 
     692    if (psz_localhome == NULL) 
     693        psz_localhome = getenv( "TMP" ); 
     694    if (psz_localhome == NULL) 
     695        psz_localhome = "/tmp"; 
    703696 
    704697    return FromLocaleDup( psz_localhome );