If $HOME is invalid, scratch together a different userdir.
authorRyan C. Gordon <icculus@icculus.org>
Sun, 21 Mar 2010 12:11:39 -0400
changeset 1072 6d3a91a5029b
parent 1070 822d91dde8e8
child 1073 b45193ab2033
If $HOME is invalid, scratch together a different userdir. Partially fixes http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=553174
src/physfs.c
--- a/src/physfs.c	Wed Mar 17 21:51:22 2010 -0400
+++ b/src/physfs.c	Sun Mar 21 12:11:39 2010 -0400
@@ -613,18 +613,21 @@
 
 static char *calculateUserDir(void)
 {
-    char *retval = NULL;
-    const char *str = NULL;
-
-    str = __PHYSFS_platformGetUserDir();
-    if (str != NULL)
-        retval = (char *) str;
-    else
+    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 */
+
+    if (retval == NULL)
     {
         const char *dirsep = PHYSFS_getDirSeparator();
         const char *uname = __PHYSFS_platformGetUserName();
-
-        str = (uname != NULL) ? uname : "default";
+        const char *str = (uname != NULL) ? uname : "default";
+
         retval = (char *) allocator.Malloc(strlen(baseDir) + strlen(str) +
                                            strlen(dirsep) + 6);
 
@@ -761,13 +764,6 @@
     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);