X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fnetradiant.git;a=blobdiff_plain;f=tools%2Fquake3%2Fq3map2%2Fpath_init.c;fp=tools%2Fquake3%2Fq3map2%2Fpath_init.c;h=ac8fa328f8501f2369d9302260eeb117264873e6;hp=6bd061350d7327034afa11167f5fcb89af4139f1;hb=d7e9dab03d4791de2c2e31e401e51941fd68f294;hpb=c2be26a9bdb2ec7ae7c817fd84885fa2a85521fb diff --git a/tools/quake3/q3map2/path_init.c b/tools/quake3/q3map2/path_init.c index 6bd06135..ac8fa328 100644 --- a/tools/quake3/q3map2/path_init.c +++ b/tools/quake3/q3map2/path_init.c @@ -66,29 +66,23 @@ char *LokiGetHomeDir( void ){ #ifndef Q_UNIX return NULL; #else + static char buf[ 4096 ]; + struct passwd pw, *pwp; char *home; - uid_t id; - struct passwd *pwd; /* get the home environment variable */ home = getenv( "HOME" ); - if ( home == NULL ) { - /* do some more digging */ - id = getuid(); - setpwent(); - while ( ( pwd = getpwent() ) != NULL ) - { - if ( pwd->pw_uid == id ) { - home = pwd->pw_dir; - break; - } - } - endpwent(); + if ( home ) { + return Q_strncpyz( buf, home, sizeof( buf ) ); } - /* return it */ - return home; + /* look up home dir in password database */ + if ( getpwuid_r( getuid(), &pw, buf, sizeof( buf ), &pwp ) == 0 ) { + return pw.pw_dir; + } + + return NULL; #endif }