From ece998dd3aa8286ec718917c448492c4ef690b29 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sat, 27 Jul 2002 06:38:28 +0000 Subject: [PATCH] Fixed basedir/userdir calculation. --- platform/os2.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/platform/os2.c b/platform/os2.c index de2f3ec1..ee6471e4 100644 --- a/platform/os2.c +++ b/platform/os2.c @@ -230,6 +230,7 @@ int __PHYSFS_platformInit(void) APIRET rc; PTIB ptib; PPIB ppib; + PHYSFS_sint32 len; assert(baseDir == NULL); @@ -237,7 +238,19 @@ int __PHYSFS_platformInit(void) 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);