Ignore:
Timestamp:
Oct 13, 2006, 6:29:26 AM (15 years ago)
Author:
joshe
Message:

Try to get home directory with getpwuid(getuid()) if getenv("HOME") fails.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/platform.c

    r920 r1000  
    3232#include "transmission.h"
    3333
     34#if !defined( SYS_BEOS ) && !defined( __AMIGAOS4__ )
     35
     36#include <pwd.h>
     37
     38static char * tr_getHomeDirectory()
     39{
     40    static char     homeDirectory[MAX_PATH_LENGTH];
     41    static int      init = 0;
     42    char          * envHome;
     43    struct passwd * pw;
     44
     45    if( init )
     46    {
     47        return homeDirectory;
     48    }
     49
     50    envHome = getenv( "HOME" );
     51    if( NULL == envHome )
     52    {
     53        pw = getpwuid( getuid() );
     54        endpwent();
     55        if( NULL == pw )
     56        {
     57            /* XXX need to handle this case */
     58            return NULL;
     59        }
     60        envHome = pw->pw_dir;
     61    }
     62
     63    snprintf( homeDirectory, MAX_PATH_LENGTH, "%s", envHome );
     64    init = 1;
     65
     66    return homeDirectory;
     67}
     68#endif /* !SYS_BEOS && !__AMIGAOS4__ */
     69
    3470static void
    3571tr_migrateResume( const char *oldDirectory, const char *newDirectory )
     
    75111#elif defined( SYS_DARWIN )
    76112    snprintf( prefsDirectory, MAX_PATH_LENGTH,
    77               "%s/Library/Caches/Transmission", getenv( "HOME" ) );
     113              "%s/Library/Caches/Transmission", tr_getHomeDirectory() );
    78114#elif defined(__AMIGAOS4__)
    79115    snprintf( prefsDirectory, MAX_PATH_LENGTH, "PROGDIR:.transmission" );
    80116#else
    81117    snprintf( prefsDirectory, MAX_PATH_LENGTH, "%s/.transmission",
    82               getenv( "HOME" ) );
     118              tr_getHomeDirectory() );
    83119#endif
    84120
     
    89125    char oldDirectory[MAX_PATH_LENGTH];
    90126    snprintf( oldDirectory, MAX_PATH_LENGTH, "%s/.transmission",
    91               getenv( "HOME" ) );
     127              tr_getHomeDirectory() );
    92128    tr_migrateResume( oldDirectory, prefsDirectory );
    93129    rmdir( oldDirectory );
     
    147183    snprintf( torrentsDirectory, MAX_PATH_LENGTH,
    148184              "%s/Library/Application Support/Transmission/Torrents",
    149               getenv( "HOME" ) );
     185              tr_getHomeDirectory() );
    150186#else
    151187    snprintf( torrentsDirectory, MAX_PATH_LENGTH, "%s/torrents",
Note: See TracChangeset for help on using the changeset viewer.