platform/os2.c
changeset 411 4907a4f94872
parent 407 81646aa3f6f8
child 412 f743cf88c61f
--- a/platform/os2.c	Sat Jul 27 06:30:02 2002 +0000
+++ b/platform/os2.c	Sat Jul 27 06:38:28 2002 +0000
@@ -230,6 +230,7 @@
     APIRET rc;
     PTIB ptib;
     PPIB ppib;
+    PHYSFS_sint32 len;
 
     assert(baseDir == NULL);
 
@@ -237,7 +238,19 @@
     rc = DosQueryModuleName(ppib->pib_hmte, sizeof (buf), (PCHAR) buf);
     BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, 0);
 
-    baseDir = (char *) malloc(strlen(buf) + 1);
+    /* chop off filename, leave path. */
+    for (len = strlen(buf) - 1; len >= 0; len--)
+    {
+        if (buf[len] == '\\')
+        {
+            buf[++len] = '\0';
+            break;
+        } /* if */
+    } /* for */
+
+    assert(len > 0);  /* should have been an "x:\\" on the front on string. */
+
+    baseDir = (char *) malloc(len + 1);
     BAIL_IF_MACRO(baseDir == NULL, ERR_OUT_OF_MEMORY, 0);
     strcpy(baseDir, buf);