]> git.eshelyaron.com Git - emacs.git/commitdiff
w32.c (readlink): Support DBCS codepages.
authorEli Zaretskii <eliz@gnu.org>
Fri, 25 Jan 2013 10:27:16 +0000 (12:27 +0200)
committerEli Zaretskii <eliz@gnu.org>
Fri, 25 Jan 2013 10:27:16 +0000 (12:27 +0200)
src/ChangeLog
src/w32.c

index c6152668a220e9d43ff853f61870077f094588ff..66eb75adca7705143df3eaba59a807a5eec6893b 100644 (file)
@@ -1,5 +1,7 @@
 2013-01-25  Eli Zaretskii  <eliz@gnu.org>
 
+       * w32.c (readlink): Support DBCS codepages.
+
        * w32notify.c (Fw32notify_add_watch): Doc fix.  (Bug#13540)
 
 2013-01-25  Dmitry Antipov  <dmantipov@yandex.ru>
index f722bc5f3974945e8cf21fa396676a11bd264b1d..dc9233ee00123dec4faa3c7dde402670348946f3 100644 (file)
--- a/src/w32.c
+++ b/src/w32.c
@@ -4639,18 +4639,34 @@ readlink (const char *name, char *buf, size_t buf_size)
          else
            {
              size_t size_to_copy = buf_size;
-             BYTE *p = lname;
+             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 (*p && p[1] == ':' && *p >= 'A' && *p <= 'Z')
-               *p += 'a' - 'A';
+             if (dbcs_p)
+               p2 = CharNextExA (file_name_codepage, p, 0);
+             else
+               p2 = p + 1;
+             if (*p && *p2 == ':' && *p >= 'A' && *p <= 'Z')
+               {
+                 *p += 'a' - 'A';
+                 p += 2;
+               }
              while (p <= pend)
                {
                  if (*p == '\\')
                    *p = '/';
-                 ++p;
+                 if (dbcs_p)
+                   {
+                     p = CharNextExA (file_name_codepage, p, 0);
+                     /* CharNextExA doesn't advance at null character.  */
+                     if (!*p)
+                       break;
+                   }
+                 else
+                   ++p;
                }
              /* Testing for null-terminated LNAME is paranoia:
                 WideCharToMultiByte should always return a