Commit 26854e9c authored by Eli Zaretskii's avatar Eli Zaretskii
Browse files

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.
parent 6ee4509a
......@@ -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 <eliz@gnu.org>
 
......
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment