diff --git a/sc2/ChangeLog b/sc2/ChangeLog index 416ee4aa1..27168720d 100644 --- a/sc2/ChangeLog +++ b/sc2/ChangeLog @@ -1,5 +1,7 @@ Changes towards version 0.4: -- Accept spaces in --contentdir argument. - SvdB +- Extra fallback for the unlikely situation that $HOME isn't set on a + unix system. (#493) - SvdB +- Accept spaces in --contentdir argument (#492) - SvdB - Separated and abstracted sound buffer-tagging and trackplayer clip/subtitle chaining -Alex - Abstracted the recursive mutexes in MixSDL and DCQ code -Michael diff --git a/sc2/src/sc2code/libs/file/dirs.c b/sc2/src/sc2code/libs/file/dirs.c index c48344366..671017525 100644 --- a/sc2/src/sc2code/libs/file/dirs.c +++ b/sc2/src/sc2code/libs/file/dirs.c @@ -31,6 +31,8 @@ #ifdef WIN32 # include # include +#else +# include #endif /* Try to find a suitable value for %APPDATA% if it isn't defined on @@ -158,11 +160,27 @@ mkdirhier (const char *path) } // Get the user's home dir -// returns a pointer to a static buffer +// returns a pointer to a static buffer from either getenv() or getpwuid(). const char * getHomeDir (void) { +#ifdef WIN32 return getenv ("HOME"); +#else + const char *home; + struct passwd *pw; + + home = getenv ("HOME"); + if (home != NULL) + return home; + + pw = getpwuid (getuid ()); + if (pw == NULL) + return NULL; + // NB: pw points to a static buffer. + + return pw->pw_name; +#endif } // Expand ~/ in a path, and replaces \ by / on Windows.