aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEli Zaretskii2013-01-25 16:34:26 +0200
committerEli Zaretskii2013-01-25 16:34:26 +0200
commit6ee4509abf626f26ef56527ca0269614285a8404 (patch)
tree49c7ebb75f78cf21db3f84392f1af2c531fd93a4 /src
parent345f866e048bdc11bc38d894a7eaaa47335443e2 (diff)
downloademacs-6ee4509abf626f26ef56527ca0269614285a8404.tar.gz
emacs-6ee4509abf626f26ef56527ca0269614285a8404.zip
Support MS-Windows file names encoded in multibyte encodings.
src/w32.c (w32_get_long_filename, init_environment, readlink): Support file names encoded in DBCS codepages.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog5
-rw-r--r--src/w32.c40
2 files changed, 33 insertions, 12 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index e9c4fe0c50e..2294a473f53 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
12013-01-25 Eli Zaretskii <eliz@gnu.org>
2
3 * w32.c (w32_get_long_filename, init_environment, readlink):
4 Support file names encoded in DBCS codepages.
5
12013-01-23 Eli Zaretskii <eliz@gnu.org> 62013-01-23 Eli Zaretskii <eliz@gnu.org>
2 7
3 * w32.c (max_filename_mbslen): New function. 8 * w32.c (max_filename_mbslen): New function.
diff --git a/src/w32.c b/src/w32.c
index 51e304af1e9..98ec573f553 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -37,7 +37,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
37/* must include CRT headers *before* config.h */ 37/* must include CRT headers *before* config.h */
38 38
39#include <config.h> 39#include <config.h>
40#include <mbstring.h> /* for _mbspbrk and _mbslwr */ 40#include <mbstring.h> /* for _mbspbrk, _mbslwr, _mbsrchr, ... */
41 41
42#undef access 42#undef access
43#undef chdir 43#undef chdir
@@ -1573,7 +1573,7 @@ w32_get_long_filename (char * name, char * buf, int size)
1573 while (p != NULL && *p) 1573 while (p != NULL && *p)
1574 { 1574 {
1575 q = p; 1575 q = p;
1576 p = strchr (q, '\\'); 1576 p = _mbschr (q, '\\');
1577 if (p) *p = '\0'; 1577 if (p) *p = '\0';
1578 len = get_long_basename (full, o, size); 1578 len = get_long_basename (full, o, size);
1579 if (len > 0) 1579 if (len > 0)
@@ -1800,16 +1800,16 @@ init_environment (char ** argv)
1800 1800
1801 if (!GetModuleFileName (NULL, modname, MAX_PATH)) 1801 if (!GetModuleFileName (NULL, modname, MAX_PATH))
1802 emacs_abort (); 1802 emacs_abort ();
1803 if ((p = strrchr (modname, '\\')) == NULL) 1803 if ((p = _mbsrchr (modname, '\\')) == NULL)
1804 emacs_abort (); 1804 emacs_abort ();
1805 *p = 0; 1805 *p = 0;
1806 1806
1807 if ((p = strrchr (modname, '\\')) && xstrcasecmp (p, "\\bin") == 0) 1807 if ((p = _mbsrchr (modname, '\\')) && xstrcasecmp (p, "\\bin") == 0)
1808 { 1808 {
1809 char buf[SET_ENV_BUF_SIZE]; 1809 char buf[SET_ENV_BUF_SIZE];
1810 1810
1811 *p = 0; 1811 *p = 0;
1812 for (p = modname; *p; p++) 1812 for (p = modname; *p; p = CharNext (p))
1813 if (*p == '\\') *p = '/'; 1813 if (*p == '\\') *p = '/';
1814 1814
1815 _snprintf (buf, sizeof (buf)-1, "emacs_dir=%s", modname); 1815 _snprintf (buf, sizeof (buf)-1, "emacs_dir=%s", modname);
@@ -1824,17 +1824,17 @@ init_environment (char ** argv)
1824 || xstrcasecmp (p, "\\AMD64") == 0)) 1824 || xstrcasecmp (p, "\\AMD64") == 0))
1825 { 1825 {
1826 *p = 0; 1826 *p = 0;
1827 p = strrchr (modname, '\\'); 1827 p = _mbsrchr (modname, '\\');
1828 if (p != NULL) 1828 if (p != NULL)
1829 { 1829 {
1830 *p = 0; 1830 *p = 0;
1831 p = strrchr (modname, '\\'); 1831 p = _mbsrchr (modname, '\\');
1832 if (p && xstrcasecmp (p, "\\src") == 0) 1832 if (p && xstrcasecmp (p, "\\src") == 0)
1833 { 1833 {
1834 char buf[SET_ENV_BUF_SIZE]; 1834 char buf[SET_ENV_BUF_SIZE];
1835 1835
1836 *p = 0; 1836 *p = 0;
1837 for (p = modname; *p; p++) 1837 for (p = modname; *p; p = CharNext (p))
1838 if (*p == '\\') *p = '/'; 1838 if (*p == '\\') *p = '/';
1839 1839
1840 _snprintf (buf, sizeof (buf)-1, "emacs_dir=%s", modname); 1840 _snprintf (buf, sizeof (buf)-1, "emacs_dir=%s", modname);
@@ -4340,18 +4340,34 @@ readlink (const char *name, char *buf, size_t buf_size)
4340 else 4340 else
4341 { 4341 {
4342 size_t size_to_copy = buf_size; 4342 size_t size_to_copy = buf_size;
4343 BYTE *p = lname; 4343 BYTE *p = lname, *p2;
4344 BYTE *pend = p + lname_len; 4344 BYTE *pend = p + lname_len;
4345 int dbcs_p = max_filename_mbslen () > 1;
4345 4346
4346 /* Normalize like dostounix_filename does, but we don't 4347 /* Normalize like dostounix_filename does, but we don't
4347 want to assume that lname is null-terminated. */ 4348 want to assume that lname is null-terminated. */
4348 if (*p && p[1] == ':' && *p >= 'A' && *p <= 'Z') 4349 if (dbcs_p)
4349 *p += 'a' - 'A'; 4350 p2 = CharNextExA (w32_ansi_code_page, p, 0);
4351 else
4352 p2 = p + 1;
4353 if (*p && *p2 == ':' && *p >= 'A' && *p <= 'Z')
4354 {
4355 *p += 'a' - 'A';
4356 p += 2;
4357 }
4350 while (p <= pend) 4358 while (p <= pend)
4351 { 4359 {
4352 if (*p == '\\') 4360 if (*p == '\\')
4353 *p = '/'; 4361 *p = '/';
4354 ++p; 4362 if (dbcs_p)
4363 {
4364 p = CharNextExA (w32_ansi_code_page, p, 0);
4365 /* CharNextExA doesn't advance at null character. */
4366 if (!*p)
4367 break;
4368 }
4369 else
4370 ++p;
4355 } 4371 }
4356 /* Testing for null-terminated LNAME is paranoia: 4372 /* Testing for null-terminated LNAME is paranoia:
4357 WideCharToMultiByte should always return a 4373 WideCharToMultiByte should always return a