Removed non-portable hacks and replaced them with more general

versions.
This commit is contained in:
Bertho Stultiens 1999-04-19 16:44:22 +00:00 committed by Alexandre Julliard
parent 0e8d8cc92b
commit 94bb5bb1a7
4 changed files with 73 additions and 19 deletions

View File

@ -4,5 +4,6 @@
WINE_MODREF *ELFDLL_LoadLibraryExA(LPCSTR libname, DWORD flags, DWORD *err);
HINSTANCE16 ELFDLL_LoadModule16(LPCSTR libname, BOOL implicit);
void ELFDLL_UnloadLibrary(WINE_MODREF *wm);
void *ELFDLL_dlopen(const char *libname, int flags);
#endif

View File

@ -25,6 +25,7 @@
#include "pe_image.h"
#include "debug.h"
#include "winerror.h"
#include "elfdll.h"
DEFAULT_DEBUG_CHANNEL(win32)
@ -138,7 +139,7 @@ WINE_MODREF *ELF_LoadLibraryExA( LPCSTR libname, DWORD flags, DWORD *err)
/* FIXME: make UNIX filename from DOS fn? */
/* ... and open it */
dlhandle = dlopen(t,RTLD_NOW);
dlhandle = ELFDLL_dlopen(t,RTLD_NOW);
if (!dlhandle) {
HeapFree( GetProcessHeap(), 0, t );
*err = ERROR_FILE_NOT_FOUND;

View File

@ -6,6 +6,7 @@
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include "config.h"
#include "windef.h"
@ -42,6 +43,70 @@ struct elfdll_image
};
/****************************************************************************
* ELFDLL_dlopen
*
* Wrapper for dlopen to search the LD_LIBRARY_PATH manually because
* libdl.so caches the environment and does not accept our changes.
*/
void *ELFDLL_dlopen(const char *libname, int flags)
{
char *ldpath = getenv("LD_LIBRARY_PATH");
char buffer[256];
int namelen;
if(!ldpath)
{
WARN(elfdll, "No LD_LIBRARY_PATH set\n");
return dlopen(libname, flags);
}
namelen = strlen(libname);
while(ldpath)
{
int len;
char *cptr;
char *from;
void *handle;
from = ldpath;
cptr = strchr(ldpath, ':');
if(!cptr)
{
len = strlen(ldpath);
ldpath = NULL;
}
else
{
len = cptr - ldpath;
ldpath = cptr + 1;
}
if(len + namelen + 1 >= sizeof(buffer))
{
ERR(elfdll, "Buffer overflow! Check LD_LIBRARY_PATH or increase buffer size.\n");
return NULL;
}
strncpy(buffer, from, len);
if(len)
{
buffer[len] = '/';
strcpy(buffer + len + 1, libname);
}
else
strcpy(buffer + len, libname);
TRACE(elfdll, "Trying dlopen('%s', %d)\n", buffer, flags);
handle = dlopen(buffer, flags);
if(handle)
return handle;
}
return NULL;
}
/****************************************************************************
* get_sobasename (internal)
*
@ -221,11 +286,8 @@ WINE_MODREF *ELFDLL_LoadLibraryExA(LPCSTR path, DWORD flags, DWORD *err)
strcpy(soname, name);
strcat(soname, ".so");
/* Try to open the elf-dll.
* The dlopen will search the correct path and our extended
* LD_LIBRARY as well.
*/
dlhandle = dlopen(soname, RTLD_LAZY);
/* Try to open the elf-dll */
dlhandle = ELFDLL_dlopen(soname, RTLD_LAZY);
if(!dlhandle)
{
WARN(elfdll, "Could not load %s (%s)\n", soname, dlerror());

View File

@ -50,7 +50,7 @@ static char *get_tok(const char *str, const char *delim)
static char *buf = NULL;
char *cptr;
if(!str && (!buf || !index))
if(!str && !buf)
return NULL;
if(str && buf)
@ -335,7 +335,6 @@ BOOL MODULE_InitLoadOrder(void)
if(nbuffer)
{
extern char *_dl_library_path;
char *ld_lib_path = getenv("LD_LIBRARY_PATH");
if(ld_lib_path)
{
@ -343,22 +342,13 @@ BOOL MODULE_InitLoadOrder(void)
* Append new path to current
*/
char *tmp = HEAP_strdupA(SystemHeap, 0, buffer);
sprintf(buffer, "%s:%s", ld_lib_path, tmp);
sprintf(buffer, "LD_LIBRARY_PATH=%s:%s", ld_lib_path, tmp);
HeapFree( SystemHeap, 0, tmp );
}
TRACE(module, "Setting new LD_LIBRARY_PATH=%s\n", buffer);
setenv("LD_LIBRARY_PATH", buffer, 1);
/*
* This is a cruel hack required to have libdl check this path.
* The problem is that libdl caches the environment variable
* and we won't get our modifications applied. We ensure the
* the correct search path by explicitely modifying the libdl
* internal variable which holds the path.
*/
_dl_library_path = HEAP_strdupA(SystemHeap, 0, buffer);
putenv(buffer);
}
/* Get the default load order */