[PATCH/cygwin]: Return correct charset in nl_langinfo

View: New views
2 Messages — Rating Filter:   Alert me  

[PATCH/cygwin]: Return correct charset in nl_langinfo

by Corinna Vinschen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I just applied the below patch, which only affects Cygwin.  Right now,
nl_langinfo(CODESET) always returns "US-ASCII" for the C locale and
it returns charsets based on the language/territory setting, which is
wrong for Cygwin.  Therefore the patch always returns the value of
__locale_charset() on Cygwin.


Corinna

        * libc/locale/nl_langinfo.c (nl_langinfo): Just return current locale
        charset on Cygwin.


Index: libc/locale/nl_langinfo.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/locale/nl_langinfo.c,v
retrieving revision 1.2
diff -u -p -r1.2 nl_langinfo.c
--- libc/locale/nl_langinfo.c 6 Jun 2003 19:57:51 -0000 1.2
+++ libc/locale/nl_langinfo.c 7 Oct 2009 16:44:54 -0000
@@ -37,10 +37,14 @@
 #include "lmonetary.h"
 #include "lmessages.h"
 
+#ifndef __CYGWIN__
 #define TRANSITION_PERIOD_HACK
+#endif
 
 #define _REL(BASE) ((int)item-BASE)
 
+extern char *__locale_charset ();
+
 char *
 _DEFUN(nl_langinfo, (item),
        nl_item item) {
@@ -54,6 +58,9 @@ _DEFUN(nl_langinfo, (item),
 
    switch (item) {
  case CODESET:
+#ifdef __CYGWIN__
+ ret = __locale_charset ();
+#else
  ret = "";
  if ((s = setlocale(LC_CTYPE, NULL)) != NULL) {
  if ((cs = strchr(s, '.')) != NULL) {
@@ -92,6 +99,7 @@ _DEFUN(nl_langinfo, (item),
   )
  ret = "US-ASCII";
  }
+#endif /* __CYGWIN__ */
  break;
  case D_T_FMT:
  ret = (char *) __get_current_time_locale()->c_fmt;

--
Corinna Vinschen
Cygwin Project Co-Leader
Red Hat

Re: [PATCH/cygwin]: Return correct charset in nl_langinfo

by Corinna Vinschen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Oct  7 18:45, Corinna Vinschen wrote:
> Hi,
>
> I just applied the below patch, which only affects Cygwin.  [...]
> * libc/locale/nl_langinfo.c (nl_langinfo): Just return current locale
> charset on Cygwin.

Unfortunately it's quite important that the KOI8 charsets return a
matching string from nl_langinfo.  I added a special case for them
for now and applied the below, still Cygwin-only patch.


Corinna


        * libc/locale/nl_langinfo.c (nl_langinfo): Add Cygwin-specific temporary
        exception for KOI8 charsets.


Index: libc/locale/nl_langinfo.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/locale/nl_langinfo.c,v
retrieving revision 1.3
diff -u -p -r1.3 nl_langinfo.c
--- libc/locale/nl_langinfo.c 7 Oct 2009 16:45:23 -0000 1.3
+++ libc/locale/nl_langinfo.c 15 Oct 2009 08:07:13 -0000
@@ -60,6 +60,12 @@ _DEFUN(nl_langinfo, (item),
  case CODESET:
 #ifdef __CYGWIN__
  ret = __locale_charset ();
+ /* Temporary exception for KOI8 charsets which are
+   incorrectly treated by calling applications otherwise. */
+ if (strcmp (ret, "CP20866") == 0)
+  ret = "KOI8-R";
+ else if (strcmp (ret, "CP21866") == 0)
+  ret = "KOI8-U";
 #else
  ret = "";
  if ((s = setlocale(LC_CTYPE, NULL)) != NULL) {


--
Corinna Vinschen
Cygwin Project Co-Leader
Red Hat