From 63bb1a85836b75f096c1cb8292501b17b7ea8d33 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Thu, 20 Feb 2025 11:50:04 +0300
Subject: [PATCH] dynapi: use DosScanEnv() for os/2.
(cherry picked from commit ee49025f80e8d7bf7b2af5478bab3b0d9d739541)
---
src/dynapi/SDL_dynapi.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/src/dynapi/SDL_dynapi.c b/src/dynapi/SDL_dynapi.c
index 48f50954aeefc..04adfd2ce77f4 100644
--- a/src/dynapi/SDL_dynapi.c
+++ b/src/dynapi/SDL_dynapi.c
@@ -440,19 +440,24 @@ extern SDL_NORETURN void SDL_ExitProcess(int exitcode);
static void SDL_InitDynamicAPILocked(void)
{
+ SDL_DYNAPI_ENTRYFN entry = NULL; /* funcs from here by default. */
+ SDL_bool use_internal = SDL_TRUE;
+
/* this can't use SDL_getenv_REAL, because it might allocate memory before the app can set their allocator */
#if defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
/* We've always used LoadLibraryA for this, so this has never worked with Unicode paths on Windows. Sorry. */
char envbuf[512]; /* overflows will just report as environment variable being unset, but LoadLibraryA has a MAX_PATH of 260 anyhow, apparently. */
const DWORD rc = GetEnvironmentVariableA(SDL_DYNAMIC_API_ENVVAR, envbuf, (DWORD) sizeof (envbuf));
char *libname = ((rc != 0) && (rc < sizeof (envbuf))) ? envbuf : NULL;
+#elif defined(__OS2__)
+ char * libname;
+ if (DosScanEnv(SDL_DYNAMIC_API_ENVVAR, &libname) != NO_ERROR) {
+ libname = NULL;
+ }
#else
char *libname = getenv(SDL_DYNAMIC_API_ENVVAR);
#endif
- SDL_DYNAPI_ENTRYFN entry = NULL; /* funcs from here by default. */
- SDL_bool use_internal = SDL_TRUE;
-
if (libname) {
while (*libname && !entry) {
char *ptr = libname;