Skip to content

Commit

Permalink
If $HOME is invalid, scratch together a different userdir.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Mar 21, 2010
1 parent 4c7d25a commit 72b232d
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions src/physfs.c
Expand Up @@ -613,18 +613,21 @@ static int freeDirHandle(DirHandle *dh, FileHandle *openList)

static char *calculateUserDir(void)
{
char *retval = NULL;
const char *str = NULL;
char *retval = __PHYSFS_platformGetUserDir();
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 (str != NULL)
retval = (char *) str;
else
if (retval == NULL)
{
const char *dirsep = PHYSFS_getDirSeparator();
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) +
strlen(dirsep) + 6);

Expand Down Expand Up @@ -761,13 +764,6 @@ int PHYSFS_init(const char *argv0)
BAIL_IF_MACRO(!appendDirSep(&baseDir), NULL, 0);

userDir = calculateUserDir();
if (userDir != NULL)
{
ptr = __PHYSFS_platformRealPath(userDir);
allocator.Free(userDir);
userDir = ptr;
} /* if */

if ((userDir == NULL) || (!appendDirSep(&userDir)))
{
allocator.Free(baseDir);
Expand Down

0 comments on commit 72b232d

Please sign in to comment.