mirror of
https://github.com/TTimo/GtkRadiant.git
synced 2024-11-14 00:41:08 +00:00
q3map2: getpwent() result may not be persistent
Use getpwuid_r() instead and store the path in a static buffer.
This commit is contained in:
parent
c2be26a9bd
commit
d7e9dab03d
1 changed files with 10 additions and 16 deletions
|
@ -66,29 +66,23 @@ char *LokiGetHomeDir( void ){
|
||||||
#ifndef Q_UNIX
|
#ifndef Q_UNIX
|
||||||
return NULL;
|
return NULL;
|
||||||
#else
|
#else
|
||||||
|
static char buf[ 4096 ];
|
||||||
|
struct passwd pw, *pwp;
|
||||||
char *home;
|
char *home;
|
||||||
uid_t id;
|
|
||||||
struct passwd *pwd;
|
|
||||||
|
|
||||||
|
|
||||||
/* get the home environment variable */
|
/* get the home environment variable */
|
||||||
home = getenv( "HOME" );
|
home = getenv( "HOME" );
|
||||||
if ( home == NULL ) {
|
if ( home ) {
|
||||||
/* do some more digging */
|
return Q_strncpyz( buf, home, sizeof( buf ) );
|
||||||
id = getuid();
|
|
||||||
setpwent();
|
|
||||||
while ( ( pwd = getpwent() ) != NULL )
|
|
||||||
{
|
|
||||||
if ( pwd->pw_uid == id ) {
|
|
||||||
home = pwd->pw_dir;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
endpwent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return it */
|
/* look up home dir in password database */
|
||||||
return home;
|
if ( getpwuid_r( getuid(), &pw, buf, sizeof( buf ), &pwp ) == 0 ) {
|
||||||
|
return pw.pw_dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue