src/platform_unix.c
changeset 1266 135cb99a06a0
parent 1265 d4098b3aa37d
child 1333 baecd71ae0e7
--- a/src/platform_unix.c	Fri Mar 23 04:54:20 2012 -0400
+++ b/src/platform_unix.c	Sat Mar 24 00:26:04 2012 -0400
@@ -141,10 +141,6 @@
 } /* __PHYSFS_platformDetectAvailableCDs */
 
 
-/* this is in posix.c ... */
-extern char *__PHYSFS_platformCopyEnvironmentVariable(const char *varname);
-
-
 /*
  * See where program (bin) resides in the $PATH specified by (envr).
  *  returns a copy of the first element in envr that contains it, or NULL
@@ -246,7 +242,7 @@
 char *__PHYSFS_platformCalcBaseDir(const char *argv0)
 {
     char *retval = NULL;
-    char *envr = NULL;
+    const char *envr = NULL;
 
     /*
      * Try to avoid using argv0 unless forced to. If there's a Linux-like
@@ -269,6 +265,11 @@
         char *ptr = strrchr(retval, '/');
         if (ptr != NULL)
             *(ptr+1) = '\0';
+        else  /* shouldn't happen, but just in case... */
+        {
+            allocator.Free(retval);
+            retval = NULL;
+        } /* else */
     } /* if */
 
     /* No /proc/self/exe, but we have an argv[0] we can parse? */
@@ -279,11 +280,15 @@
             return NULL;  /* higher level parses out real path from argv0. */
 
         /* If there's no dirsep on argv0, then look through $PATH for it. */
-        /* !!! FIXME: smallAlloc? */
-        envr = __PHYSFS_platformCopyEnvironmentVariable("PATH");
-        BAIL_IF_MACRO(!envr, ERRPASS, NULL);
-        retval = findBinaryInPath(argv0, envr);
-        allocator.Free(envr);
+        envr = getenv("PATH");
+        if (envr != NULL)
+        {
+            char *path = (char *) __PHYSFS_smallAlloc(strlen(envr) + 1);
+            BAIL_IF_MACRO(!path, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
+            strcpy(path, envr);
+            retval = findBinaryInPath(argv0, path);
+            __PHYSFS_smallFree(path);
+        } /* if */
     } /* if */
 
     if (retval != NULL)