[newlib-cygwin] Introduce __current_locale_charset/__locale_charset

Corinna Vinschen corinna@sourceware.org
Sat Aug 20 15:45:00 GMT 2016


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=7630e384623f778b88be8926e2c2a2e6fcbd9008

commit 7630e384623f778b88be8926e2c2a2e6fcbd9008
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Sat Aug 20 16:05:56 2016 +0200

    Introduce __current_locale_charset/__locale_charset
    
    The former __locale_charset always fetched the current locale's charset.
    We need the per-locale charset, too, in future. Rename __locale_charset
    to __current_locale_charset and change __locale_charset to take a
    locale_t as parameter.  Accommodate througout.
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 newlib/libc/ctype/jp2uc.c        |  6 +++---
 newlib/libc/locale/nl_langinfo.c |  2 +-
 newlib/libc/locale/setlocale.h   | 12 +++++++++++-
 winsup/cygwin/nlsfuncs.cc        |  3 ++-
 winsup/cygwin/regex/regcomp.c    |  4 ++--
 5 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/newlib/libc/ctype/jp2uc.c b/newlib/libc/ctype/jp2uc.c
index 40d777a..f5bd7db 100644
--- a/newlib/libc/ctype/jp2uc.c
+++ b/newlib/libc/ctype/jp2uc.c
@@ -154,11 +154,11 @@ _DEFUN (__jp2uc, (c, type), wint_t c _AND int type)
 wint_t
 _DEFUN (_jp2uc, (c), wint_t c)
 {
-  if (!strcmp (__locale_charset (), "JIS"))
+  if (!strcmp (__current_locale_charset (), "JIS"))
     c = __jp2uc (c, JP_JIS);
-  else if (!strcmp (__locale_charset (), "SJIS"))
+  else if (!strcmp (__current_locale_charset (), "SJIS"))
     c = __jp2uc (c, JP_SJIS);
-  else if (!strcmp (__locale_charset (), "EUCJP"))
+  else if (!strcmp (__current_locale_charset (), "EUCJP"))
     c = __jp2uc (c, JP_EUCJP);
   return c;
 }
diff --git a/newlib/libc/locale/nl_langinfo.c b/newlib/libc/locale/nl_langinfo.c
index c7e27cf..5acfb9a 100644
--- a/newlib/libc/locale/nl_langinfo.c
+++ b/newlib/libc/locale/nl_langinfo.c
@@ -212,7 +212,7 @@ _DEFUN(nl_langinfo, (item),
 #endif /* __HAVE_LOCALE_INFO__ */
 	case CODESET:
 #ifdef __CYGWIN__
-		ret = (char *) __locale_charset ();
+		ret = (char *) __current_locale_charset ();
 #endif
 do_codeset:
 #ifdef __CYGWIN__
diff --git a/newlib/libc/locale/setlocale.h b/newlib/libc/locale/setlocale.h
index 4275750..99bd466 100644
--- a/newlib/libc/locale/setlocale.h
+++ b/newlib/libc/locale/setlocale.h
@@ -373,7 +373,17 @@ __get_current_messages_locale (void)
 #endif /* !__HAVE_LOCALE_INFO__ */
 
 _ELIDABLE_INLINE const char *
-__locale_charset (void)
+__locale_charset (struct __locale_t *locale)
+{
+#ifdef __HAVE_LOCALE_INFO__
+  return __get_ctype_locale (locale)->codeset;
+#else
+  return locale->ctype_codeset;
+#endif
+}
+
+_ELIDABLE_INLINE const char *
+__current_locale_charset (void)
 {
 #ifdef __HAVE_LOCALE_INFO__
   return __get_current_ctype_locale ()->codeset;
diff --git a/winsup/cygwin/nlsfuncs.cc b/winsup/cygwin/nlsfuncs.cc
index 9ff1ef2..3e3b5f4 100644
--- a/winsup/cygwin/nlsfuncs.cc
+++ b/winsup/cygwin/nlsfuncs.cc
@@ -1527,7 +1527,8 @@ internal_setlocale ()
   if (cygheap->locale.mbtowc == __global_locale.mbtowc)
     return;
 
-  debug_printf ("Cygwin charset chang to %s", __locale_charset ());
+  debug_printf ("Global charset set to %s",
+		__locale_charset (&__global_locale));
   /* Fetch PATH and CWD and convert to wchar_t in previous charset. */
   path = getenv ("PATH");
   if (path && *path)	/* $PATH can be potentially unset. */
diff --git a/winsup/cygwin/regex/regcomp.c b/winsup/cygwin/regex/regcomp.c
index 0dc59ff..63ca4f1 100644
--- a/winsup/cygwin/regex/regcomp.c
+++ b/winsup/cygwin/regex/regcomp.c
@@ -1132,7 +1132,7 @@ wgetnext(struct parse *p)
 	   invalid ASCII chars.  To be more Linux-compatible, we align the
 	   behaviour to glibc here.  Allow any character value if the current
 	   local's codeset is ASCII. */
-	if (*__locale_charset () == 'A') /* SCII */
+	if (*__current_locale_charset () == 'A') /* SCII */
 	  return (wint_t) (unsigned char) *p->next++;
 #endif
 	memset(&mbs, 0, sizeof(mbs));
@@ -1503,7 +1503,7 @@ findmust(struct parse *p, struct re_guts *g)
 	 */
 	if (MB_CUR_MAX > 1 &&
 #ifdef __CYGWIN__
-	    strcmp(__locale_charset (), "UTF-8") != 0)
+	    strcmp(__current_locale_charset (), "UTF-8") != 0)
 #else
 	    strcmp(_CurrentRuneLocale->__encoding, "UTF-8") != 0)
 #endif



More information about the Cygwin-cvs mailing list