X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=os2%2Fdl_os2.c;h=b698451b085d6af442eaa5b86d8cf2d90bcc2b5f;hb=e0e3c57ad9f042b7ff4eb12755ee3feaad30892b;hp=19f36f6aa7fa9cfd59986b644342a89cee0606ce;hpb=c692d6706f16a6480546327c33c922f46f377826;p=p5sagit%2Fp5-mst-13.2.git diff --git a/os2/dl_os2.c b/os2/dl_os2.c index 19f36f6..b698451 100644 --- a/os2/dl_os2.c +++ b/os2/dl_os2.c @@ -1,23 +1,41 @@ #include "dlfcn.h" +#include "string.h" +#include "stdio.h" #define INCL_BASE #include static ULONG retcode; +static char fail[300]; + +#ifdef PERL_CORE + +#include "EXTERN.h" +#include "perl.h" + +#else + +char *os2error(int rc); + +#endif void * -dlopen(char *path, int mode) +dlopen(const char *path, int mode) { HMODULE handle; - char tmp[260], *beg, *dot; - char fail[300]; + char tmp[260]; + const char *beg, *dot; ULONG rc; - if ((rc = DosLoadModule(fail, sizeof fail, path, &handle)) == 0) + fail[0] = 0; + if ((rc = DosLoadModule(fail, sizeof fail, (char*)path, &handle)) == 0) return (void *)handle; retcode = rc; + if (strlen(path) >= sizeof(tmp)) + return NULL; + /* Not found. Check for non-FAT name and try truncated name. */ /* Don't know if this helps though... */ for (beg = dot = path + strlen(path); @@ -27,6 +45,7 @@ dlopen(char *path, int mode) dot = beg; if (dot - beg > 8) { int n = beg+8-path; + memmove(tmp, path, n); memmove(tmp+n, dot, strlen(dot)+1); if (DosLoadModule(fail, sizeof fail, tmp, &handle) == 0) @@ -37,11 +56,12 @@ dlopen(char *path, int mode) } void * -dlsym(void *handle, char *symbol) +dlsym(void *handle, const char *symbol) { ULONG rc, type; PFN addr; + fail[0] = 0; rc = DosQueryProcAddr((HMODULE)handle, 0, symbol, &addr); if (rc == 0) { rc = DosQueryProcType((HMODULE)handle, 0, symbol, &type); @@ -56,16 +76,30 @@ dlsym(void *handle, char *symbol) char * dlerror(void) { - static char buf[300]; + static char buf[700]; ULONG len; + char *err; if (retcode == 0) return NULL; - if (DosGetMessage(NULL, 0, buf, sizeof buf - 1, retcode, "OSO001.MSG", &len)) - sprintf(buf, "OS/2 system error code %d", retcode); - else - buf[len] = '\0'; + err = os2error(retcode); + len = strlen(err); + if (len > sizeof(buf) - 1) + len = sizeof(buf) - 1; + strncpy(buf, err, len+1); + if (fail[0] && len < 300) + sprintf(buf + len, ", possible problematic module: '%s'", fail); retcode = 0; return buf; } +int +dlclose(void *handle) +{ + ULONG rc; + + if ((rc = DosFreeModule((HMODULE)handle)) == 0) return 0; + + retcode = rc; + return 2; +}