]> Savannah Git Hosting - gnulib.git/commitdiff
localcharset: Optimize code for native Windows.
authorBruno Haible <bruno@clisp.org>
Tue, 17 Dec 2019 14:02:12 +0000 (15:02 +0100)
committerBruno Haible <bruno@clisp.org>
Tue, 17 Dec 2019 14:07:12 +0000 (15:07 +0100)
* lib/localcharset.c (locale_charset): Don't both calling
setlocale (LC_ALL, NULL) since we're not interested in its result.

ChangeLog
lib/localcharset.c

index a42ab8efe6b8cce57d25b10140699d68b04e7529..da868d5443e4db0ae79b26875747280cb326d8da 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2019-12-17  Bruno Haible  <bruno@clisp.org>
+
+       localcharset: Optimize code for native Windows.
+       * lib/localcharset.c (locale_charset): Don't both calling
+       setlocale (LC_ALL, NULL) since we're not interested in its result.
+
 2019-12-17  Bruno Haible  <bruno@clisp.org>
 
        nl_langinfo: Fix multithread-safety bug on OpenBSD 3.8.
index 8d17e4c8f8b1ab9572b020026c71fd3fcbe64ebf..126f085ac7727e591647e4cc9a38017d74378970 100644 (file)
@@ -901,27 +901,20 @@ locale_charset (void)
      'setlocale' call specified.  So we use it as a last resort, in
      case the string returned by 'setlocale' doesn't specify the
      codepage.  */
-  char *current_locale = setlocale (LC_ALL, NULL);
-  char *pdot;
+  char *current_locale = setlocale (LC_CTYPE, NULL);
+  char *pdot = strrchr (current_locale, '.');
 
-  /* If they set different locales for different categories,
-     'setlocale' will return a semi-colon separated list of locale
-     values.  To make sure we use the correct one, we choose LC_CTYPE.  */
-  if (strchr (current_locale, ';'))
-    current_locale = setlocale (LC_CTYPE, NULL);
-
-  pdot = strrchr (current_locale, '.');
   if (pdot && 2 + strlen (pdot + 1) + 1 <= sizeof (buf))
     sprintf (buf, "CP%s", pdot + 1);
   else
     {
       /* The Windows API has a function returning the locale's codepage as a
-        number: GetACP().
-        When the output goes to a console window, it needs to be provided in
-        GetOEMCP() encoding if the console is using a raster font, or in
-        GetConsoleOutputCP() encoding if it is using a TrueType font.
-        But in GUI programs and for output sent to files and pipes, GetACP()
-        encoding is the best bet.  */
+         number: GetACP().
+         When the output goes to a console window, it needs to be provided in
+         GetOEMCP() encoding if the console is using a raster font, or in
+         GetConsoleOutputCP() encoding if it is using a TrueType font.
+         But in GUI programs and for output sent to files and pipes, GetACP()
+         encoding is the best bet.  */
       sprintf (buf, "CP%u", GetACP ());
     }
   /* For a locale name such as "French_France.65001", in Windows 10,