From bae5c76d0c4d04a33d0dfca3658db17b31fd10e0 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Thu, 20 Mar 2003 19:26:18 +0000 Subject: [PATCH] Moved dlopen wrappers to loader.c. --- library/loader.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++ library/port.c | 94 ----------------------------------------------- 2 files changed, 95 insertions(+), 94 deletions(-) diff --git a/library/loader.c b/library/loader.c index d97043580db..86e448504e9 100644 --- a/library/loader.c +++ b/library/loader.c @@ -405,3 +405,98 @@ void *wine_dll_load_main_exe( const char *name, char *error, int errorsize, int { return dlopen_dll( name, error, errorsize, test_only ); } + + +/* + * These functions provide wrappers around dlopen() and associated + * functions. They work around a bug in glibc 2.1.x where calling + * a dl*() function after a previous dl*() function has failed + * without a dlerror() call between the two will cause a crash. + * They all take a pointer to a buffer that + * will receive the error description (from dlerror()). This + * parameter may be NULL if the error description is not required. + */ + +/*********************************************************************** + * wine_dlopen + */ +void *wine_dlopen( const char *filename, int flag, char *error, int errorsize ) +{ +#ifdef HAVE_DLOPEN + void *ret; + const char *s; + dlerror(); dlerror(); + ret = dlopen( filename, flag ); + s = dlerror(); + if (error) + { + strncpy( error, s ? s : "", errorsize ); + error[errorsize - 1] = '\0'; + } + dlerror(); + return ret; +#else + if (error) + { + strncpy( error, "dlopen interface not detected by configure", errorsize ); + error[errorsize - 1] = '\0'; + } + return NULL; +#endif +} + +/*********************************************************************** + * wine_dlsym + */ +void *wine_dlsym( void *handle, const char *symbol, char *error, int errorsize ) +{ +#ifdef HAVE_DLOPEN + void *ret; + const char *s; + dlerror(); dlerror(); + ret = dlsym( handle, symbol ); + s = dlerror(); + if (error) + { + strncpy( error, s ? s : "", errorsize ); + error[errorsize - 1] = '\0'; + } + dlerror(); + return ret; +#else + if (error) + { + strncpy( error, "dlopen interface not detected by configure", errorsize ); + error[errorsize - 1] = '\0'; + } + return NULL; +#endif +} + +/*********************************************************************** + * wine_dlclose + */ +int wine_dlclose( void *handle, char *error, int errorsize ) +{ +#ifdef HAVE_DLOPEN + int ret; + const char *s; + dlerror(); dlerror(); + ret = dlclose( handle ); + s = dlerror(); + if (error) + { + strncpy( error, s ? s : "", errorsize ); + error[errorsize - 1] = '\0'; + } + dlerror(); + return ret; +#else + if (error) + { + strncpy( error, "dlopen interface not detected by configure", errorsize ); + error[errorsize - 1] = '\0'; + } + return 1; +#endif +} diff --git a/library/port.c b/library/port.c index 2d0df4dccb1..fcaec419713 100644 --- a/library/port.c +++ b/library/port.c @@ -248,100 +248,6 @@ void *wine_anon_mmap( void *start, size_t size, int prot, int flags ) } -/* - * These functions provide wrappers around dlopen() and associated - * functions. They work around a bug in glibc 2.1.x where calling - * a dl*() function after a previous dl*() function has failed - * without a dlerror() call between the two will cause a crash. - * They all take a pointer to a buffer that - * will receive the error description (from dlerror()). This - * parameter may be NULL if the error description is not required. - */ - -/*********************************************************************** - * wine_dlopen - */ -void *wine_dlopen( const char *filename, int flag, char *error, int errorsize ) -{ -#ifdef HAVE_DLOPEN - void *ret; - const char *s; - dlerror(); dlerror(); - ret = dlopen( filename, flag ); - s = dlerror(); - if (error) - { - strncpy( error, s ? s : "", errorsize ); - error[errorsize - 1] = '\0'; - } - dlerror(); - return ret; -#else - if (error) - { - strncpy( error, "dlopen interface not detected by configure", errorsize ); - error[errorsize - 1] = '\0'; - } - return NULL; -#endif -} - -/*********************************************************************** - * wine_dlsym - */ -void *wine_dlsym( void *handle, const char *symbol, char *error, int errorsize ) -{ -#ifdef HAVE_DLOPEN - void *ret; - const char *s; - dlerror(); dlerror(); - ret = dlsym( handle, symbol ); - s = dlerror(); - if (error) - { - strncpy( error, s ? s : "", errorsize ); - error[errorsize - 1] = '\0'; - } - dlerror(); - return ret; -#else - if (error) - { - strncpy( error, "dlopen interface not detected by configure", errorsize ); - error[errorsize - 1] = '\0'; - } - return NULL; -#endif -} - -/*********************************************************************** - * wine_dlclose - */ -int wine_dlclose( void *handle, char *error, int errorsize ) -{ -#ifdef HAVE_DLOPEN - int ret; - const char *s; - dlerror(); dlerror(); - ret = dlclose( handle ); - s = dlerror(); - if (error) - { - strncpy( error, s ? s : "", errorsize ); - error[errorsize - 1] = '\0'; - } - dlerror(); - return ret; -#else - if (error) - { - strncpy( error, "dlopen interface not detected by configure", errorsize ); - error[errorsize - 1] = '\0'; - } - return 1; -#endif -} - #ifndef HAVE_ECVT /*********************************************************************** * ecvt