From fb478d4b62e4390cbb3650a98a3b8749c818fb47 Mon Sep 17 00:00:00 2001 From: Dirk Zimoch Date: Tue, 21 Oct 2025 12:01:51 +0200 Subject: [PATCH] fix loading libraries with relative paths in Windows --- require.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/require.c b/require.c index c27baaa..23b8f6b 100644 --- a/require.c +++ b/require.c @@ -323,12 +323,12 @@ static HMODULE loadlib(const char* libname) } #elif defined (_WIN32) { - char *p; - char *libpath = strdup(libname); - if ((p = strrchr(libpath, '/')) != NULL) - *p = '\0'; - SetDllDirectory(libpath); - if ((libhandle = LoadLibrary(libname)) == NULL) + char *libpath = realpath(libname, NULL); + if (libpath == NULL) { + fprintf (stderr, "Loading %s library failed: out of memory\n", libname); + return NULL; + } + if ((libhandle = LoadLibrary(libpath)) == NULL) { LPSTR lpMsgBuf; @@ -345,7 +345,6 @@ static HMODULE loadlib(const char* libname) LocalFree(lpMsgBuf); } free(libpath); - SetDllDirectory(NULL); } #elif defined (vxWorks) {