OS/2: actually working again, now.

This commit is contained in:
Ryan C. Gordon 2017-07-07 13:55:52 -04:00
parent 683216def8
commit 4cbffd39e8

View File

@ -94,14 +94,14 @@ static PHYSFS_ErrorCode errcodeFromAPIRET(const APIRET rc)
return PHYSFS_ERR_OTHER_ERROR; return PHYSFS_ERR_OTHER_ERROR;
} /* errcodeFromAPIRET */ } /* errcodeFromAPIRET */
static char *cvtUtf8ToCodepage(const char *cpstr) static char *cvtUtf8ToCodepage(const char *utf8str)
{ {
if (uconvdll) if (uconvdll)
{ {
int rc; int rc;
size_t len = strlen(cpstr) + 1; size_t len = strlen(utf8str) + 1;
const size_t uc2buflen = len * sizeof (UniChar); const size_t uc2buflen = len * sizeof (UniChar);
UniChar *uc2ptr = (char *) __PHYSFS_smallAlloc(uc2buflen); UniChar *uc2ptr = (UniChar *) __PHYSFS_smallAlloc(uc2buflen);
UniChar *uc2str = uc2ptr; UniChar *uc2str = uc2ptr;
char *cpptr = NULL; char *cpptr = NULL;
char *cpstr = NULL; char *cpstr = NULL;
@ -110,7 +110,7 @@ static char *cvtUtf8ToCodepage(const char *cpstr)
size_t cplen; size_t cplen;
GOTO_IF(!uc2str, PHYSFS_ERR_OUT_OF_MEMORY, failed); GOTO_IF(!uc2str, PHYSFS_ERR_OUT_OF_MEMORY, failed);
PHYSFS_utf8ToUcs2(cpstr, (const PHYSFS_uint16 *) uc2str, uc2buflen); PHYSFS_utf8ToUcs2(utf8str, (PHYSFS_uint16 *) uc2str, uc2buflen);
for (unilen = 0; uc2str[unilen]; unilen++) { /* spin */ } for (unilen = 0; uc2str[unilen]; unilen++) { /* spin */ }
unilen++; /* null terminator. */ unilen++; /* null terminator. */
@ -119,10 +119,9 @@ static char *cvtUtf8ToCodepage(const char *cpstr)
GOTO_IF(!cpptr, PHYSFS_ERR_OUT_OF_MEMORY, failed); GOTO_IF(!cpptr, PHYSFS_ERR_OUT_OF_MEMORY, failed);
cpstr = cpptr; cpstr = cpptr;
rc = pUniUconvFromUcs(uconv, &uc2str, &unilen, (void **) &cpstr, &cplen, &uc2str, &subs); rc = pUniUconvFromUcs(uconv, &uc2str, &unilen, (void **) &cpstr, &cplen, &subs);
GOTO_IF(rc != ULS_SUCCESS, PHYSFS_ERR_BAD_FILENAME, failed); GOTO_IF(rc != ULS_SUCCESS, PHYSFS_ERR_BAD_FILENAME, failed);
GOTO_IF(subs > 0, PHYSFS_ERR_BAD_FILENAME, failed); GOTO_IF(subs > 0, PHYSFS_ERR_BAD_FILENAME, failed);
assert(len == 0);
assert(unilen == 0); assert(unilen == 0);
return cpptr; return cpptr;
@ -152,8 +151,7 @@ static char *cvtCodepageToUtf8(const char *cpstr)
rc = pUniUconvToUcs(uconv, (void **) &cpstr, &cplen, &uc2str, &unilen, &subs); rc = pUniUconvToUcs(uconv, (void **) &cpstr, &cplen, &uc2str, &unilen, &subs);
GOTO_IF(rc != ULS_SUCCESS, PHYSFS_ERR_BAD_FILENAME, done); GOTO_IF(rc != ULS_SUCCESS, PHYSFS_ERR_BAD_FILENAME, done);
GOTO_IF(subs > 0, PHYSFS_ERR_BAD_FILENAME, done); GOTO_IF(subs > 0, PHYSFS_ERR_BAD_FILENAME, done);
assert(len == 0); assert(cplen == 0);
assert(unilen == 0);
retval = (char *) allocator.Malloc(len * 4); retval = (char *) allocator.Malloc(len * 4);
GOTO_IF(!retval, PHYSFS_ERR_OUT_OF_MEMORY, done); GOTO_IF(!retval, PHYSFS_ERR_OUT_OF_MEMORY, done);
PHYSFS_utf8FromUcs2((const PHYSFS_uint16 *) uc2ptr, retval, len * 4); PHYSFS_utf8FromUcs2((const PHYSFS_uint16 *) uc2ptr, retval, len * 4);
@ -181,7 +179,7 @@ static char *cvtPathToCorrectCase(char *buf)
* If there's an error, or the path has vanished for some reason, it * If there's an error, or the path has vanished for some reason, it
* won't hurt to have the original case, so we just keep going. * won't hurt to have the original case, so we just keep going.
*/ */
while (fname != NULL) while ((fname != NULL) && (*fname != '\0'))
{ {
char spec[CCHMAXPATH]; char spec[CCHMAXPATH];
FILEFINDBUF3 fb; FILEFINDBUF3 fb;
@ -436,7 +434,7 @@ void __PHYSFS_platformEnumerateFiles(const char *dirname,
utf8 = cvtCodepageToUtf8(fb.achName); utf8 = cvtCodepageToUtf8(fb.achName);
if (utf8) if (utf8)
{ {
callback(callbackdata, origdir, fb.achName); callback(callbackdata, origdir, utf8);
allocator.Free(utf8); allocator.Free(utf8);
} /* if */ } /* if */
} /* if */ } /* if */