2.11.2
[platform/upstream/glib.git] / gmodule / gmodule-win32.c
index 9811496..bf63091 100644 (file)
@@ -5,23 +5,23 @@
  * Copyright (C) 1998 Tor Lillqvist
  *
  * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
+ * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
- * Library General Public License for more details.
+ * Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU Library General Public
+ * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  * Boston, MA 02111-1307, USA.
  */
 
 /*
- * Modified by the GLib Team and others 1997-1999.  See the AUTHORS
+ * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
  * file for a list of people on the GLib Team.  See the ChangeLog
  * files for a list of changes.  These files are distributed with
  * GLib at ftp://ftp.gtk.org/pub/gtk/. 
 #include <stdio.h>
 #include <windows.h>
 
-#ifdef __MSVC__
 #include <tlhelp32.h>
-#else
-
-/* The w32api headers supplied with the mingw gcc don't have
- * tlhelp32.h. We really only need the MODULEENTRY32 struct and the
- * TH32CS_SNAPMODULE value, so provide them here.
- */
-
-#define MAX_MODULE_NAME32 255
-
-typedef struct
-{
-  DWORD dwSize;
-  DWORD th32ModuleID;
-  DWORD th32ProcessID;
-  DWORD GlblcntUsage;
-  DWORD ProccntUsage;
-  BYTE  *modBaseAddr; 
-  DWORD modBaseSize; 
-  HMODULE hModule;     
-  char szModule[MAX_MODULE_NAME32 + 1];
-  char szExePath[MAX_PATH];
-} MODULEENTRY32;
-#define TH32CS_SNAPMODULE 8
 
+#ifdef G_WITH_CYGWIN
+#include <sys/cygwin.h>
 #endif
 
 static void
@@ -74,11 +52,31 @@ set_error (void)
 /* --- functions --- */
 static gpointer
 _g_module_open (const gchar *file_name,
-               gboolean     bind_lazy)
+               gboolean     bind_lazy,
+               gboolean     bind_local)
 {
   HINSTANCE handle;
+#ifdef G_WITH_CYGWIN
+  gchar tmp[MAX_PATH];
+
+  cygwin_conv_to_win32_path(file_name, tmp);
+  file_name = tmp;
+#endif
+  if (G_WIN32_HAVE_WIDECHAR_API ())
+    {
+      wchar_t *wfilename = g_utf8_to_utf16 (file_name, -1, NULL, NULL, NULL);
   
-  handle = LoadLibrary (file_name);
+      handle = LoadLibraryW (wfilename);
+      g_free (wfilename);
+    }
+  else
+    {
+      gchar *cp_filename = g_locale_from_utf8 (file_name, -1, NULL, NULL, NULL);
+
+      handle = LoadLibraryA (cp_filename);
+      g_free (cp_filename);
+    }
+      
   if (!handle)
     set_error ();
 
@@ -239,15 +237,34 @@ _g_module_build_path (const gchar *directory,
                      const gchar *module_name)
 {
   gint k;
-  
+
   k = strlen (module_name);
+    
   if (directory && *directory)
-    if (k > 4 && g_strcasecmp (module_name + k - 4, ".dll") == 0)
-      return g_strconcat (directory, "\\", module_name, NULL);
+    if (k > 4 && g_ascii_strcasecmp (module_name + k - 4, ".dll") == 0)
+      return g_strconcat (directory, G_DIR_SEPARATOR_S, module_name, NULL);
+#ifdef G_WITH_CYGWIN
+    else if (strncmp (module_name, "lib", 3) == 0 || strncmp (module_name, "cyg", 3) == 0)
+      return g_strconcat (directory, G_DIR_SEPARATOR_S, module_name, ".dll", NULL);
+    else
+      return g_strconcat (directory, G_DIR_SEPARATOR_S, "cyg", module_name, ".dll", NULL);
+#else
+    else if (strncmp (module_name, "lib", 3) == 0)
+      return g_strconcat (directory, G_DIR_SEPARATOR_S, module_name, ".dll", NULL);
     else
-      return g_strconcat (directory, "\\", module_name, ".dll", NULL);
-  else if (k > 4 && g_strcasecmp (module_name + k - 4, ".dll") == 0)
+      return g_strconcat (directory, G_DIR_SEPARATOR_S, "lib", module_name, ".dll", NULL);
+#endif
+  else if (k > 4 && g_ascii_strcasecmp (module_name + k - 4, ".dll") == 0)
     return g_strdup (module_name);
+#ifdef G_WITH_CYGWIN
+  else if (strncmp (module_name, "lib", 3) == 0 || strncmp (module_name, "cyg", 3) == 0)
+    return g_strconcat (module_name, ".dll", NULL);
   else
+    return g_strconcat ("cyg", module_name, ".dll", NULL);
+#else
+  else if (strncmp (module_name, "lib", 3) == 0)
     return g_strconcat (module_name, ".dll", NULL);
+  else
+    return g_strconcat ("lib", module_name, ".dll", NULL);
+#endif
 }