]> git.eshelyaron.com Git - emacs.git/commitdiff
(readdir): If FindFirstFile/FindNextFile return in cFileName a file name that
authorEli Zaretskii <eliz@gnu.org>
Sat, 22 Mar 2008 11:53:40 +0000 (11:53 +0000)
committerEli Zaretskii <eliz@gnu.org>
Sat, 22 Mar 2008 11:53:40 +0000 (11:53 +0000)
includes `?' characters, use the 8+3 alias in cAlternateFileName instead.

src/ChangeLog
src/w32.c

index da936e544dbb910c310f09d27d3bc9eff4ff1486..7e010850b19aff29838581d68c1b5614a739f288 100644 (file)
@@ -1,3 +1,9 @@
+2008-03-22  Eli Zaretskii  <eliz@gnu.org>
+
+       * w32.c (readdir): If FindFirstFile/FindNextFile return in
+       cFileName a file name that includes `?' characters, use the 8+3
+       alias in cAlternateFileName instead.
+
 2008-03-21  Stefan Monnier  <monnier@iro.umontreal.ca>
 
        * buffer.c (enlarge_buffer_text): Fix int -> EMACS_INT.
index 3107af8f4a1057dfae012502d455537cf388ee13..24921687c9e2697793f1bb07f3c334f54d2a632e 100644 (file)
--- a/src/w32.c
+++ b/src/w32.c
@@ -1889,6 +1889,8 @@ closedir (DIR *dirp)
 struct direct *
 readdir (DIR *dirp)
 {
+  int downcase = !NILP (Vw32_downcase_file_names);
+
   if (wnet_enum_handle != INVALID_HANDLE_VALUE)
     {
       if (!read_unc_volume (wnet_enum_handle,
@@ -1923,14 +1925,23 @@ readdir (DIR *dirp)
      value returned by stat().  */
   dir_static.d_ino = 1;
 
+  strcpy (dir_static.d_name, dir_find_data.cFileName);
+
+  /* If the file name in cFileName[] includes `?' characters, it means
+     the original file name used characters that cannot be represented
+     by the current ANSI codepage.  To avoid total lossage, retrieve
+     the short 8+3 alias of the long file name.  */
+  if (_mbspbrk (dir_static.d_name, "?"))
+    {
+      strcpy (dir_static.d_name, dir_find_data.cAlternateFileName);
+      downcase = 1;    /* 8+3 aliases are returned in all caps */
+    }
+  dir_static.d_namlen = strlen (dir_static.d_name);
   dir_static.d_reclen = sizeof (struct direct) - MAXNAMLEN + 3 +
     dir_static.d_namlen - dir_static.d_namlen % 4;
-
-  dir_static.d_namlen = strlen (dir_find_data.cFileName);
-  strcpy (dir_static.d_name, dir_find_data.cFileName);
   if (dir_is_fat)
     _strlwr (dir_static.d_name);
-  else if (!NILP (Vw32_downcase_file_names))
+  else if (downcase)
     {
       register char *p;
       for (p = dir_static.d_name; *p; p++)