From fd1d8cdc09ed86e4a0812120a17ff0d7b04adcaf Mon Sep 17 00:00:00 2001 From: matz Date: Fri, 16 Jan 1998 12:19:22 +0000 Subject: *** empty log message *** git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/RUBY@11 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- dln.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 62 insertions(+), 9 deletions(-) (limited to 'dln.c') diff --git a/dln.c b/dln.c index 23edc6f3fc..f4ab012021 100644 --- a/dln.c +++ b/dln.c @@ -24,6 +24,12 @@ char *dln_argv0; #include #endif +#ifdef HAVE_STRING_H +# include +#else +# include +#endif + void *xmalloc(); void *xcalloc(); void *xrealloc(); @@ -47,15 +53,8 @@ void *xrealloc(); # include #endif -#if defined (HAVE_STRING_H) -# include -#else -# include -#endif - #ifndef NT char *strdup(); - char *getenv(); #endif @@ -1069,7 +1068,6 @@ dln_sym(name) #ifdef _AIX #include /* for isdigit() */ #include /* for global errno */ -#include /* for strerror() */ #include #endif @@ -1077,6 +1075,10 @@ dln_sym(name) /*#include */ #endif +#ifdef _WIN32 +#include +#endif + static char * dln_strerror() { @@ -1104,6 +1106,20 @@ dln_strerror() #ifdef USE_DLN_DLOPEN return (char*)dlerror(); #endif + +#ifdef _WIN32 + static char message[1024]; + FormatMessage( + FORMAT_MESSAGE_FROM_SYSTEM, + NULL, + GetLastError(), + MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), + message, + sizeof message, + NULL); + + return message; +#endif } @@ -1159,6 +1175,43 @@ void dln_load(file) char *file; { +#ifdef _WIN32 + HINSTANCE handle; + char winfile[255]; + void (*init_fct)(); + char buf[MAXPATHLEN]; + + /* Load the file as an object one */ + init_funcname(buf, file); + +#ifdef __CYGWIN32__ + cygwin32_conv_to_win32_path(file, winfile); +#else + strcpy(winfile, file); +#endif + + /* Load file */ + if ((handle = + LoadLibraryExA(winfile, NULL, LOAD_WITH_ALTERED_SEARCH_PATH)) == NULL) { + printf("LoadLibraryExA\n"); + goto failed; + } + +#ifdef __CYGWIN32__ + init_fct = (void(*)())GetProcAddress(handle, "impure_setup"); + + if (init_fct) + init_fct(_impure_ptr); +#endif + + if ((init_fct = (void(*)())GetProcAddress(handle, buf)) == NULL) { + printf("GetProcAddress %s\n", buf); + goto failed; + } + /* Call the init code */ + (*init_fct)(); + return; +#else #ifdef USE_DLN_A_OUT if (load(file) == -1) { goto failed; @@ -1175,7 +1228,6 @@ dln_load(file) { void *handle; void (*init_fct)(); - int len = strlen(file); # ifndef RTLD_LAZY # define RTLD_LAZY 1 @@ -1280,6 +1332,7 @@ dln_load(file) #endif #endif /* USE_DLN_A_OUT */ +#endif #if !defined(_AIX) && !defined(NeXT) failed: LoadError("%s - %s", dln_strerror(), file); -- cgit v1.2.3