[PATCH/cygwin]: Switch to UTF-8 charset by default in the C locale
Corinna Vinschen
vinschen@redhat.com
Mon Sep 28 16:44:00 GMT 2009
Hi,
I applied the below patch. It affects only Cygwin, which now switches
to the UTF-8 charset as default charset in the C locale.
Corinna
* libc/locale/locale.c (lc_ctype_charset): Set to "UTF-8" on Cygwin.
(lc_message_charset): Ditto.
(loadlocale): Set charset of the "C" locale to "UTF-8" on Cygwin.
* libc/stdlib/mbtowc_r.c (__mbtowc): Default to __utf8_mbtowc on
Cygwin.
* libc/stdlib/wctomb_r.c (__wctomb): Default to __utf8_wctomb on
Cygwin.
Index: libc/locale/locale.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/locale/locale.c,v
retrieving revision 1.26
diff -u -p -r1.26 locale.c
--- libc/locale/locale.c 23 Sep 2009 17:19:00 -0000 1.26
+++ libc/locale/locale.c 27 Sep 2009 12:20:14 -0000
@@ -225,8 +225,13 @@ static const char *__get_locale_env(stru
#endif
+#ifdef __CYGWIN__
+static char lc_ctype_charset[ENCODING_LEN + 1] = "UTF-8";
+static char lc_message_charset[ENCODING_LEN + 1] = "UTF-8";
+#else
static char lc_ctype_charset[ENCODING_LEN + 1] = "ASCII";
static char lc_message_charset[ENCODING_LEN + 1] = "ASCII";
+#endif
static int lc_ctype_cjk_lang = 0;
char *
@@ -428,7 +433,11 @@ loadlocale(struct _reent *p, int categor
if (!strcmp (locale, "POSIX"))
strcpy (locale, "C");
if (!strcmp (locale, "C")) /* Default "C" locale */
+#ifdef __CYGWIN__
+ strcpy (charset, "UTF-8");
+#else
strcpy (charset, "ASCII");
+#endif
else if (locale[0] == 'C' && locale[1] == '-') /* Old newlib style */
strcpy (charset, locale + 2);
else /* POSIX style */
Index: libc/stdlib/mbtowc_r.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdlib/mbtowc_r.c,v
retrieving revision 1.15
diff -u -p -r1.15 mbtowc_r.c
--- libc/stdlib/mbtowc_r.c 29 Jul 2009 08:31:30 -0000 1.15
+++ libc/stdlib/mbtowc_r.c 27 Sep 2009 12:20:14 -0000
@@ -9,7 +9,11 @@
int (*__mbtowc) (struct _reent *, wchar_t *, const char *, size_t,
const char *, mbstate_t *)
+#ifdef __CYGWIN__
+ = __utf8_mbtowc;
+#else
= __ascii_mbtowc;
+#endif
int
_DEFUN (_mbtowc_r, (r, pwc, s, n, state),
Index: libc/stdlib/wctomb_r.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdlib/wctomb_r.c,v
retrieving revision 1.14
diff -u -p -r1.14 wctomb_r.c
--- libc/stdlib/wctomb_r.c 9 Apr 2009 08:20:10 -0000 1.14
+++ libc/stdlib/wctomb_r.c 27 Sep 2009 12:20:14 -0000
@@ -8,7 +8,11 @@
int (*__wctomb) (struct _reent *, char *, wchar_t, const char *charset,
mbstate_t *)
+#ifdef __CYGWIN__
+ = __utf8_wctomb;
+#else
= __ascii_wctomb;
+#endif
int
_DEFUN (_wctomb_r, (r, s, wchar, state),
--
Corinna Vinschen
Cygwin Project Co-Leader
Red Hat
More information about the Newlib
mailing list