From: Gary V. Vaughan Date: Wed, 16 Jun 1999 14:58:45 +0000 (+0000) Subject: * libltdl/ltdl.c (sys_wll_open): libltdl expects this function to X-Git-Tag: release-1-3-3~12 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=515998e7cc851992163ef305410649ba11ef2204;p=thirdparty%2Flibtool.git * libltdl/ltdl.c (sys_wll_open): libltdl expects this function to fail if it is unable to physically load the library. Sadly, LoadLibrary will search the loaded libraries for a match and return one of them if the path search load fails. Simulate a failure in this case for compatibility with the other APIs. Also, LoadLibrary takes the liberty of adding `.dll' to library names passed without an extension, we now add a trailing `.' to prevent this from happening. --- diff --git a/ChangeLog b/ChangeLog index 851713b62..a9e1382d6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,20 @@ +1999-06-16 Gary V. Vaughan + + * libltdl/ltdl.c (sys_wll_open): libltdl expects this function to + fail if it is unable to physically load the library. Sadly, + LoadLibrary will search the loaded libraries for a match and + return one of them if the path search load fails. Simulate a + failure in this case for compatibility with the other APIs. + Also, LoadLibrary takes the liberty of adding `.dll' to library + names passed without an extension, we now add a trailing `.' to + prevent this from happening. + 1999-06-15 Gary V. Vaughan * libltdl/ltdl.c (sys_wll_close): Strangely enough, Microsoft have decided that LoadLibrary returns `0' for success, yet FreeLibrary returns `0' for failure! The FreeLibrary call used to interpret - `0' as success for both functions. + `0' as success. 1999-06-14 Thomas Tanner diff --git a/libltdl/ltdl.c b/libltdl/ltdl.c index dbee31cb7..119dcd71c 100644 --- a/libltdl/ltdl.c +++ b/libltdl/ltdl.c @@ -514,16 +514,56 @@ sys_wll_exit LTDL_PARAMS((void)) return 0; } +/* Forward declaration; required to implement handle search below. */ +static lt_dlhandle handles; + static int sys_wll_open (handle, filename) lt_dlhandle handle; const char *filename; { - handle->handle = LoadLibrary(filename); - if (!handle->handle) { + lt_dlhandle cur; + char *searchname = NULL; + char *ext = strrchr(filename, '.'); + + if (ext) { + /* FILENAME already has an extension. */ + searchname = strdup(filename); + } else { + /* Append a `.' to stop Windows from adding an + implicit `.dll' extension. */ + searchname = (char*)lt_dlmalloc(2+ strlen(filename)); + strcpy(searchname, filename); + strcat(searchname, "."); + } + + handle->handle = LoadLibrary(searchname); + lt_dlfree(searchname); + + /* libltdl expects this function to fail if it is unable + to physically load the library. Sadly, LoadLibrary + will search the loaded libraries for a match and return + one of them if the path search load fails. + + We check whether LoadLibrary is returning a handle to + an already loaded module, and simulate failure if we + find one. */ + cur = handles; + while (cur) { + if (!cur->handle) { + cur = 0; + break; + } + if (cur->handle == handle->handle) + break; + cur = cur->next; + } + + if (cur || !handle->handle) { last_error = cannot_open_error; return 1; } + return 0; }