SDL_GetBasePath() fixes for OS/2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
diff --git a/src/filesystem/os2/SDL_sysfilesystem.c b/src/filesystem/os2/SDL_sysfilesystem.c
index e8050cb..3203f0b 100644
--- a/src/filesystem/os2/SDL_sysfilesystem.c
+++ b/src/filesystem/os2/SDL_sysfilesystem.c
@@ -31,6 +31,7 @@
#define INCL_DOSFILEMGR
#define INCL_DOSPROCESS
+#define INCL_DOSMODULEMGR
#define INCL_DOSERRORS
#include <os2.h>
@@ -42,30 +43,31 @@ SDL_GetBasePath(void)
PPIB pib;
ULONG ulRC = DosGetInfoBlocks(&tib, &pib);
PCHAR pcEnd;
- ULONG cbResult;
CHAR acBuf[CCHMAXPATH];
if (ulRC != NO_ERROR) {
- debug_os2("DosGetInfoBlocks() failed, rc = %u", ulRC);
+ SDL_SetError("Can't get process information block (E%lu)", ulRC);
return NULL;
}
- pcEnd = SDL_strrchr(pib->pib_pchcmd, '\\');
+ ulRC = DosQueryModuleName(pib->pib_hmte, sizeof(acBuf), acBuf);
+ if (ulRC != NO_ERROR) {
+ SDL_SetError("Can't query the module name (E%lu)", ulRC);
+ return NULL;
+ }
+
+ pcEnd = SDL_strrchr(acBuf, '\\');
if (pcEnd != NULL)
- pcEnd++;
+ pcEnd[1] = '\0';
else {
- if (pib->pib_pchcmd[1] == ':')
- pcEnd = &pib->pib_pchcmd[2];
+ if (acBuf[1] == ':') /* e.g. "C:FOO" */
+ acBuf[2] = '\0';
else {
- SDL_SetError("No path in pib->pib_pchcmd");
+ SDL_SetError("No path in module name");
return NULL;
}
}
- cbResult = pcEnd - pib->pib_pchcmd;
- SDL_memcpy(acBuf, pib->pib_pchcmd, cbResult);
- acBuf[cbResult] = '\0';
-
return OS2_SysToUTF8(acBuf);
}