From 2f9adccc9bcbbcb4d8c38074efde9c9741c76211 Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 11 Apr 2010 07:48:14 +0000 Subject: * ruby.c (DllMain, ruby_init_loadpath): use DLL instance handle given to DllMain instead of VirtualQuery so that loadpath becomes relative from the DLL on WinCE too. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@27306 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ruby.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'ruby.c') diff --git a/ruby.c b/ruby.c index b88c0f5955..cd821aa988 100644 --- a/ruby.c +++ b/ruby.c @@ -242,6 +242,24 @@ ruby_incpush(path) #define LOAD_RELATIVE 1 #endif +#if defined _WIN32 || defined __CYGWIN__ +static HMODULE libruby; + +BOOL WINAPI +DllMain(HINSTANCE dll, DWORD reason, LPVOID reserved) +{ + if (reason == DLL_PROCESS_ATTACH) + libruby = dll; + return TRUE; +} + +HANDLE +rb_libruby_handle(void) +{ + return libruby; +} +#endif + void ruby_init_loadpath() { @@ -251,27 +269,20 @@ ruby_init_loadpath() char libpath[FILENAME_MAX+1]; size_t baselen; char *p; -#if defined _WIN32 || defined __CYGWIN__ - HMODULE libruby = NULL; - MEMORY_BASIC_INFORMATION m; -#ifndef _WIN32_WCE - memset(&m, 0, sizeof(m)); - if (VirtualQuery(ruby_init_loadpath, &m, sizeof(m)) && m.State == MEM_COMMIT) - libruby = (HMODULE)m.AllocationBase; -#endif +#if defined _WIN32 || defined __CYGWIN__ GetModuleFileName(libruby, libpath, sizeof libpath); #elif defined(DJGPP) extern char *__dos_argv0; - strncpy(libpath, __dos_argv0, FILENAME_MAX); + strncpy(libpath, __dos_argve0, sizeof(libpath) - 1); #elif defined(__human68k__) extern char **_argv; - strncpy(libpath, _argv[0], FILENAME_MAX); + strncpy(libpath, _argv[0], sizeof(libpath) - 1); #elif defined(__EMX__) - _execname(libpath, FILENAME_MAX); + _execname(libpath, sizeof(libpath) - 1); #endif - libpath[FILENAME_MAX] = '\0'; + libpath[sizeof(libpath) - 1] = '\0'; #if defined DOSISH translate_char(libpath, '\\', '/'); #elif defined __CYGWIN__ -- cgit v1.2.3