See if $HOME is bogus, and if so, use getpwuid() instead.

Should fully fix http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=553174
This commit is contained in:
Ryan C. Gordon 2010-03-21 12:20:44 -04:00
parent 72b232d4f5
commit efa498fd5d
1 changed files with 13 additions and 0 deletions

View File

@ -97,8 +97,21 @@ char *__PHYSFS_platformGetUserName(void)
char *__PHYSFS_platformGetUserDir(void)
{
char *retval = __PHYSFS_platformCopyEnvironmentVariable("HOME");
/* if the environment variable was set, make sure it's really a dir. */
if (retval != NULL)
{
struct stat statbuf;
if ((stat(retval, &statbuf) == -1) || (S_ISDIR(statbuf.st_mode) == 0))
{
allocator.Free(retval);
retval = NULL;
} /* if */
} /* if */
if (retval == NULL)
retval = getUserDirByUID();
return retval;
} /* __PHYSFS_platformGetUserDir */