From 26854e9c9ee5469474bcaa496b94273082772c18 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Fri, 25 Jan 2013 16:47:37 +0200 Subject: [PATCH] Use file-name-coding-system when decoding symlinks on MS-Windows. src/w32.c (readlink): Use the current file-name-coding-system, not the ANSI codepage, to decode and handle targets of symlinks. --- src/ChangeLog | 2 ++ src/w32.c | 11 +++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 2294a473f53..cd71fa73db0 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -2,6 +2,8 @@ * w32.c (w32_get_long_filename, init_environment, readlink): Support file names encoded in DBCS codepages. + (readlink): Use the current file-name-coding-system, not the ANSI + codepage, to decode and handle targets of symlinks. 2013-01-23 Eli Zaretskii diff --git a/src/w32.c b/src/w32.c index 98ec573f553..86b4ea72a22 100644 --- a/src/w32.c +++ b/src/w32.c @@ -4305,6 +4305,8 @@ readlink (const char *name, char *buf, size_t buf_size) WCHAR *lwname_src = reparse_data->SymbolicLinkReparseBuffer.PathBuffer + reparse_data->SymbolicLinkReparseBuffer.PrintNameOffset/sizeof(WCHAR); + /* This updates file_name_codepage which we need below. */ + int dbcs_p = max_filename_mbslen () > 1; /* According to MSDN, PrintNameLength does not include the terminating null character. */ @@ -4312,9 +4314,7 @@ readlink (const char *name, char *buf, size_t buf_size) memcpy (lwname, lwname_src, lwname_len); lwname[lwname_len/sizeof(WCHAR)] = 0; /* null-terminate */ - /* FIXME: Should we use the current file-name coding system - instead of the fixed value of the ANSI codepage? */ - lname_len = WideCharToMultiByte (w32_ansi_code_page, 0, lwname, -1, + lname_len = WideCharToMultiByte (file_name_codepage, 0, lwname, -1, lname, MAX_PATH, NULL, NULL); if (!lname_len) { @@ -4342,12 +4342,11 @@ readlink (const char *name, char *buf, size_t buf_size) size_t size_to_copy = buf_size; BYTE *p = lname, *p2; BYTE *pend = p + lname_len; - int dbcs_p = max_filename_mbslen () > 1; /* Normalize like dostounix_filename does, but we don't want to assume that lname is null-terminated. */ if (dbcs_p) - p2 = CharNextExA (w32_ansi_code_page, p, 0); + p2 = CharNextExA (file_name_codepage, p, 0); else p2 = p + 1; if (*p && *p2 == ':' && *p >= 'A' && *p <= 'Z') @@ -4361,7 +4360,7 @@ readlink (const char *name, char *buf, size_t buf_size) *p = '/'; if (dbcs_p) { - p = CharNextExA (w32_ansi_code_page, p, 0); + p = CharNextExA (file_name_codepage, p, 0); /* CharNextExA doesn't advance at null character. */ if (!*p) break; -- 2.39.2