If $HOME is invalid, scratch together a different userdir.

Partially fixes http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=553174
This commit is contained in:
Ryan C. Gordon 2010-03-21 12:11:39 -04:00
parent 4c7d25aebe
commit 72b232d4f5
1 changed files with 10 additions and 14 deletions

View File

@ -613,18 +613,21 @@ static int freeDirHandle(DirHandle *dh, FileHandle *openList)
static char *calculateUserDir(void) static char *calculateUserDir(void)
{ {
char *retval = NULL; char *retval = __PHYSFS_platformGetUserDir();
const char *str = NULL; if (retval != NULL)
{
/* make sure it really exists and is normalized. */
char *ptr = __PHYSFS_platformRealPath(retval);
allocator.Free(retval);
retval = ptr;
} /* if */
str = __PHYSFS_platformGetUserDir(); if (retval == NULL)
if (str != NULL)
retval = (char *) str;
else
{ {
const char *dirsep = PHYSFS_getDirSeparator(); const char *dirsep = PHYSFS_getDirSeparator();
const char *uname = __PHYSFS_platformGetUserName(); const char *uname = __PHYSFS_platformGetUserName();
const char *str = (uname != NULL) ? uname : "default";
str = (uname != NULL) ? uname : "default";
retval = (char *) allocator.Malloc(strlen(baseDir) + strlen(str) + retval = (char *) allocator.Malloc(strlen(baseDir) + strlen(str) +
strlen(dirsep) + 6); strlen(dirsep) + 6);
@ -761,13 +764,6 @@ int PHYSFS_init(const char *argv0)
BAIL_IF_MACRO(!appendDirSep(&baseDir), NULL, 0); BAIL_IF_MACRO(!appendDirSep(&baseDir), NULL, 0);
userDir = calculateUserDir(); userDir = calculateUserDir();
if (userDir != NULL)
{
ptr = __PHYSFS_platformRealPath(userDir);
allocator.Free(userDir);
userDir = ptr;
} /* if */
if ((userDir == NULL) || (!appendDirSep(&userDir))) if ((userDir == NULL) || (!appendDirSep(&userDir)))
{ {
allocator.Free(baseDir); allocator.Free(baseDir);