aboutsummaryrefslogtreecommitdiffstats
path: root/src/w32.c
diff options
context:
space:
mode:
authorEli Zaretskii <[email protected]>2008-03-26 19:06:04 +0000
committerEli Zaretskii <[email protected]>2008-03-26 19:06:04 +0000
commit192788d7def835d08708c3387c778538b63f2475 (patch)
tree865d64c3b4a353fcc45a901edaf62b8441e1f657 /src/w32.c
parenta8da49fb71368e5069302bca516d429ba6c57d78 (diff)
(readdir): If FindFirstFile/FindNextFile return in cFileName a file name that
includes `?' characters, use the 8+3 alias in cAlternateFileName instead.
Diffstat (limited to 'src/w32.c')
-rw-r--r--src/w32.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/w32.c b/src/w32.c
index 8a970e0c25..e40f9a4b28 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -1779,6 +1779,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,
@@ -1816,11 +1818,23 @@ readdir (DIR *dirp)
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 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_find_data.cFileName, "?"))
+ {
+ strcpy (dir_static.d_name, dir_find_data.cAlternateFileName);
+ /* 8+3 aliases are returned in all caps, which could break
+ various alists that look at filenames' extensions. */
+ downcase = 1;
+ }
+ else
+ strcpy (dir_static.d_name, dir_find_data.cFileName);
+ dir_static.d_namlen = strlen (dir_static.d_name);
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++)