From afec5165194e5d44c0af4f6f20e26e29aab79cdf Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Mon, 9 Dec 2013 21:18:58 +0200 Subject: [PATCH] Fixed file-truename when w32-unicode-filenames is nil, fixed its doc. --- src/w32.c | 18 ++++++++++++++---- src/w32term.c | 4 +++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/w32.c b/src/w32.c index 7e32da84c58..db0b4fee485 100644 --- a/src/w32.c +++ b/src/w32.c @@ -2123,7 +2123,7 @@ parse_root (const char * name, const char ** pPath) static int get_long_basename (char * name, char * buf, int size) { - HANDLE dir_handle; + HANDLE dir_handle = INVALID_HANDLE_VALUE; char fname_utf8[MAX_UTF8_PATH]; int len = 0; int cstatus = -1; @@ -2148,9 +2148,19 @@ get_long_basename (char * name, char * buf, int size) WIN32_FIND_DATAA find_data_ansi; filename_to_ansi (name, fname_ansi); - dir_handle = FindFirstFileA (fname_ansi, &find_data_ansi); - if (dir_handle != INVALID_HANDLE_VALUE) - cstatus = filename_from_ansi (find_data_ansi.cFileName, fname_utf8); + /* If the ANSI name includes ? characters, it is not encodable + in the ANSI codepage. In that case, we deliver the question + marks to the caller; calling FindFirstFileA in this case + could return some unrelated file name in the same + directory. */ + if (_mbspbrk (fname_ansi, "?")) + cstatus = filename_from_ansi (fname_ansi, fname_utf8); + else + { + dir_handle = FindFirstFileA (fname_ansi, &find_data_ansi); + if (dir_handle != INVALID_HANDLE_VALUE) + cstatus = filename_from_ansi (find_data_ansi.cFileName, fname_utf8); + } } if (cstatus == 0 && (len = strlen (fname_utf8)) < size) diff --git a/src/w32term.c b/src/w32term.c index 64febea6a1a..2b91aa99dc2 100644 --- a/src/w32term.c +++ b/src/w32term.c @@ -6674,7 +6674,9 @@ specified by `file-name-coding-system'. This variable is set to non-nil by default when Emacs runs on Windows systems of the NT family, including W2K, XP, Vista, Windows 7 and -Windows 8. It is set to nil on Windows 9X. */); +Windows 8. It is set to nil on Windows 9X. + +Do NOT change the value of this variable, except for debugging purposes! */); w32_unicode_filenames = 0; /* Tell Emacs about this window system. */ -- 2.39.2