src/platform_posix.c
changeset 1073 b45193ab2033
parent 1054 57f4af811ffb
child 1098 4e86cec1143f
--- a/src/platform_posix.c	Sun Mar 21 12:11:39 2010 -0400
+++ b/src/platform_posix.c	Sun Mar 21 12:20:44 2010 -0400
@@ -97,8 +97,21 @@
 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 */