]> code.delx.au - gnu-emacs/blobdiff - src/w32.c
Merge from origin/emacs-25
[gnu-emacs] / src / w32.c
index ea3a9dafad5d48bb5bc313160ba55af9d834971b..183a4e7e9d9239dd6493632d6506747cd07d6cbc 100644 (file)
--- a/src/w32.c
+++ b/src/w32.c
@@ -484,6 +484,7 @@ typedef DWORD (WINAPI *GetAdaptersInfo_Proc) (
 
 int (WINAPI *pMultiByteToWideChar)(UINT,DWORD,LPCSTR,int,LPWSTR,int);
 int (WINAPI *pWideCharToMultiByte)(UINT,DWORD,LPCWSTR,int,LPSTR,int,LPCSTR,LPBOOL);
+DWORD multiByteToWideCharFlags;
 
   /* ** A utility function ** */
 static BOOL
@@ -1550,8 +1551,8 @@ codepage_for_filenames (CPINFO *cp_info)
 int
 filename_to_utf16 (const char *fn_in, wchar_t *fn_out)
 {
-  int result = pMultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS, fn_in, -1,
-                                    fn_out, MAX_PATH);
+  int result = pMultiByteToWideChar (CP_UTF8, multiByteToWideCharFlags, fn_in,
+                                    -1, fn_out, MAX_PATH);
 
   if (!result)
     {
@@ -1641,8 +1642,8 @@ filename_from_ansi (const char *fn_in, char *fn_out)
 {
   wchar_t fn_utf16[MAX_PATH];
   int codepage = codepage_for_filenames (NULL);
-  int result = pMultiByteToWideChar (codepage, MB_ERR_INVALID_CHARS, fn_in, -1,
-                                    fn_utf16, MAX_PATH);
+  int result = pMultiByteToWideChar (codepage, multiByteToWideCharFlags, fn_in,
+                                    -1, fn_utf16, MAX_PATH);
 
   if (!result)
     {
@@ -9104,14 +9105,14 @@ check_windows_init_file (void)
                   "not unpacked properly.\nSee the README.W32 file in the "
                   "top-level Emacs directory for more information.",
                   init_file_name, load_path);
-         needed = pMultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS, buffer,
-                                        -1, NULL, 0);
+         needed = pMultiByteToWideChar (CP_UTF8, multiByteToWideCharFlags,
+                                        buffer, -1, NULL, 0);
          if (needed > 0)
            {
              wchar_t *msg_w = alloca ((needed + 1) * sizeof (wchar_t));
 
-             pMultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS, buffer, -1,
-                                   msg_w, needed);
+             pMultiByteToWideChar (CP_UTF8, multiByteToWideCharFlags, buffer,
+                                   -1, msg_w, needed);
              needed = pWideCharToMultiByte (CP_ACP, 0, msg_w, -1,
                                             NULL, 0, NULL, NULL);
              if (needed > 0)
@@ -9298,6 +9299,7 @@ maybe_load_unicows_dll (void)
            (MultiByteToWideChar_Proc)GetProcAddress (ret, "MultiByteToWideChar");
          pWideCharToMultiByte =
            (WideCharToMultiByte_Proc)GetProcAddress (ret, "WideCharToMultiByte");
+          multiByteToWideCharFlags = MB_ERR_INVALID_CHARS;
          return ret;
        }
       else
@@ -9327,6 +9329,11 @@ maybe_load_unicows_dll (void)
         pointers; no need for the LoadLibrary dance.  */
       pMultiByteToWideChar = MultiByteToWideChar;
       pWideCharToMultiByte = WideCharToMultiByte;
+      /* On NT 4.0, though, MB_ERR_INVALID_CHARS is not supported.  */
+      if (w32_major_version < 5)
+        multiByteToWideCharFlags = 0;
+      else
+        multiByteToWideCharFlags = MB_ERR_INVALID_CHARS;
       return LoadLibrary ("Gdi32.dll");
     }
 }