summaryrefslogtreecommitdiffstats
path: root/libiconv-1.16-wchar.patch
blob: ed518009ac37b8ed2668c1b2e6b8e6148f3cc561 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
commit 6a8348e65546fab85e79cea7da5c5b44c3ac80c9
Author: Lemures Lemniscati <lemures.lemniscati@gmail.com>
Date:   Sat Jul 11 10:11:35 2020 +0900

    1.16-wchar.patch

diff --git a/libcharset/lib/localcharset.c b/libcharset/lib/localcharset.c
index 3effe1d..462aade 100644
--- a/libcharset/lib/localcharset.c
+++ b/libcharset/lib/localcharset.c
@@ -51,10 +51,6 @@
 #   include <locale.h>
 #  endif
 # endif
-# ifdef __CYGWIN__
-#  define WIN32_LEAN_AND_MEAN
-#  include <windows.h>
-# endif
 #elif defined WINDOWS_NATIVE
 # define WIN32_LEAN_AND_MEAN
 # include <windows.h>
@@ -692,64 +688,12 @@ locale_charset (void)
 
 # if HAVE_LANGINFO_CODESET
 
-  /* Most systems support nl_langinfo (CODESET) nowadays.  */
-  codeset = nl_langinfo (CODESET);
-
-#  ifdef __CYGWIN__
-  /* Cygwin < 1.7 does not have locales.  nl_langinfo (CODESET) always
-     returns "US-ASCII".  Return the suffix of the locale name from the
-     environment variables (if present) or the codepage as a number.  */
-  if (codeset != NULL && strcmp (codeset, "US-ASCII") == 0)
-    {
-      const char *locale;
-      static char buf[2 + 10 + 1];
-
-      locale = getenv ("LC_ALL");
-      if (locale == NULL || locale[0] == '\0')
-        {
-          locale = getenv ("LC_CTYPE");
-          if (locale == NULL || locale[0] == '\0')
-            locale = getenv ("LANG");
-        }
-      if (locale != NULL && locale[0] != '\0')
-        {
-          /* If the locale name contains an encoding after the dot, return
-             it.  */
-          const char *dot = strchr (locale, '.');
-
-          if (dot != NULL)
-            {
-              const char *modifier;
-
-              dot++;
-              /* Look for the possible @... trailer and remove it, if any.  */
-              modifier = strchr (dot, '@');
-              if (modifier == NULL)
-                return dot;
-              if (modifier - dot < sizeof (buf))
-                {
-                  memcpy (buf, dot, modifier - dot);
-                  buf [modifier - dot] = '\0';
-                  return buf;
-                }
-            }
-        }
-
-      /* The Windows API has a function returning the locale's codepage as a
-         number: GetACP().  This encoding is used by Cygwin, unless the user
-         has set the environment variable CYGWIN=codepage:oem (which very few
-         people do).
-         Output directed to console windows needs to be converted (to
-         GetOEMCP() if the console is using a raster font, or to
-         GetConsoleOutputCP() if it is using a TrueType font).  Cygwin does
-         this conversion transparently (see winsup/cygwin/fhandler_console.cc),
-         converting to GetConsoleOutputCP().  This leads to correct results,
-         except when SetConsoleOutputCP has been called and a raster font is
-         in use.  */
-      sprintf (buf, "CP%u", GetACP ());
-      codeset = buf;
-    }
-#  endif
+  /* Most systems support nl_langinfo (CODESET) nowadays.
+     POSIX allows that the returned pointer may point to a static area that
+     may be overwritten by subsequent calls to setlocale or nl_langinfo. */
+  static char codeset_buf[64];
+  codeset_buf[0] = '\0';
+  codeset = strncat (codeset_buf, nl_langinfo (CODESET), sizeof (codeset_buf));
 
   if (codeset == NULL)
     /* The canonical name cannot be determined.  */