Merge commit '3f1b5efccaa727745b335b546a42bd650694ca08' into main
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
diff --git a/src/loadso/os2/SDL_sysloadso.c b/src/loadso/os2/SDL_sysloadso.c
index 4af8068..292196e 100644
--- a/src/loadso/os2/SDL_sysloadso.c
+++ b/src/loadso/os2/SDL_sysloadso.c
@@ -47,11 +47,20 @@ SDL_LoadObject(const char *sofile)
pszModName = OS2_UTF8ToSys(sofile);
ulRC = DosLoadModule(acError, sizeof(acError), pszModName, &hModule);
- SDL_free(pszModName);
+
+ if (ulRC != NO_ERROR && !SDL_strrchr(pszModName, '\\') && !SDL_strrchr(pszModName, '/')) {
+ /* strip .dll extension and retry only if name has no path. */
+ size_t len = SDL_strlen(pszModName);
+ if (len > 4 && SDL_strcasecmp(&pszModName[len - 4], ".dll") == 0) {
+ pszModName[len - 4] = '\0';
+ ulRC = DosLoadModule(acError, sizeof(acError), pszModName, &hModule);
+ }
+ }
if (ulRC != NO_ERROR) {
SDL_SetError("Failed loading %s: %s (E%u)", sofile, acError, ulRC);
- return NULL;
+ hModule = NULLHANDLE;
}
+ SDL_free(pszModName);
return (void *)hModule;
}
@@ -64,6 +73,16 @@ SDL_LoadFunction(void *handle, const char *name)
ulRC = DosQueryProcAddr((HMODULE)handle, 0, name, &pFN);
if (ulRC != NO_ERROR) {
+ /* retry with an underscore prepended, e.g. for gcc-built dlls. */
+ SDL_bool isstack;
+ size_t len = SDL_strlen(name) + 1;
+ char *_name = SDL_small_alloc(char, len + 1, &isstack);
+ _name[0] = '_';
+ SDL_memcpy(&_name[1], name, len);
+ ulRC = DosQueryProcAddr((HMODULE)handle, 0, _name, &pFN);
+ SDL_small_free(_name, isstack);
+ }
+ if (ulRC != NO_ERROR) {
SDL_SetError("Failed loading procedure %s (E%u)", name, ulRC);
return NULL;
}