Skip to content

Commit

Permalink
SDL_GetBasePath() fixes for OS/2
Browse files Browse the repository at this point in the history
  • Loading branch information
sezero committed Mar 17, 2022
1 parent b2db570 commit dfbe1f7
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/filesystem/os2/SDL_sysfilesystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#define INCL_DOSFILEMGR
#define INCL_DOSPROCESS
#define INCL_DOSMODULEMGR
#define INCL_DOSERRORS
#include <os2.h>

Expand All @@ -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);
}

Expand Down

0 comments on commit dfbe1f7

Please sign in to comment.