]> git.eshelyaron.com Git - emacs.git/commitdiff
Converted and fixed w32_delayed_load.
authorEli Zaretskii <eliz@gnu.org>
Sat, 16 Nov 2013 17:47:06 +0000 (19:47 +0200)
committerEli Zaretskii <eliz@gnu.org>
Sat, 16 Nov 2013 17:47:06 +0000 (19:47 +0200)
src/w32.c

index ac2878a95fd956f6b77beb3c5237bcf859d10385..6f8a59c570329c0a31275ebff860f66e60438e43 100644 (file)
--- a/src/w32.c
+++ b/src/w32.c
@@ -8119,7 +8119,7 @@ sys_localtime (const time_t *t)
 HMODULE
 w32_delayed_load (Lisp_Object library_id)
 {
-  HMODULE library_dll = NULL;
+  HMODULE dll_handle = NULL;
 
   CHECK_SYMBOL (library_id);
 
@@ -8132,26 +8132,56 @@ w32_delayed_load (Lisp_Object library_id)
       if (CONSP (dlls))
         for (dlls = XCDR (dlls); CONSP (dlls); dlls = XCDR (dlls))
           {
-            CHECK_STRING_CAR (dlls);
-            if ((library_dll = LoadLibrary (SDATA (XCAR (dlls)))))
-              {
-                char name[MAX_PATH];
-                DWORD len;
-
-                len = GetModuleFileNameA (library_dll, name, sizeof (name));
-                found = Fcons (XCAR (dlls),
-                               (len > 0)
-                               /* Possibly truncated */
-                               ? make_specified_string (name, -1, len, 1)
-                               : Qnil);
-                break;
-              }
-          }
+           Lisp_Object dll = XCAR (dlls);
+           char name[MAX_UTF8_PATH];
+           DWORD res = -1;
+
+           CHECK_STRING (dll);
+           dll = ENCODE_FILE (dll);
+           if (w32_unicode_filenames)
+             {
+               wchar_t name_w[MAX_PATH];
+
+               filename_to_utf16 (SSDATA (dll), name_w);
+               dll_handle = LoadLibraryW (name_w);
+               if (dll_handle)
+                 {
+                   res = GetModuleFileNameW (dll_handle, name_w,
+                                             sizeof (name_w));
+                   if (res > 0)
+                     filename_from_utf16 (name_w, name);
+                 }
+             }
+           else
+             {
+               char name_a[MAX_PATH];
+
+               filename_to_ansi (SSDATA (dll), name_a);
+               dll_handle = LoadLibraryA (name_a);
+               if (dll_handle)
+                 {
+                   res = GetModuleFileNameA (dll_handle, name_a,
+                                             sizeof (name_a));
+                   if (res > 0)
+                     filename_from_ansi (name_a, name);
+                 }
+             }
+           if (dll_handle)
+             {
+               ptrdiff_t len = strlen (name);
+               found = Fcons (dll,
+                              (res > 0)
+                              /* Possibly truncated */
+                              ? make_specified_string (name, -1, len, 1)
+                              : Qnil);
+               break;
+             }
+         }
 
       Fput (library_id, QCloaded_from, found);
     }
 
-  return library_dll;
+  return dll_handle;
 }
 
 \f
@@ -8170,6 +8200,12 @@ check_windows_init_file (void)
       Lisp_Object init_file;
       int fd;
 
+      /* Implementation note: this function runs early during Emacs
+        startup, before startup.el is run.  So Vload_path is still in
+        its initial unibyte form, holding ANSI-encoded file names.
+        That is why we never bother to ENCODE_FILE here, nor use wide
+        APIs for file names: we will never get UTF-8 encoded file
+        names here.  */
       init_file = build_string ("term/w32-win");
       fd = openp (Vload_path, init_file, Fget_load_suffixes (), NULL, Qnil);
       if (fd < 0)