view src/readline-4-locale.patch @ 7199:ea296e38047a default tip @

maint: Merge release to default.
author Markus Mützel <markus.muetzel@gmx.de>
date Thu, 16 May 2024 11:42:51 +0200
parents a6f1111a9f1d
children
line wrap: on
line source

--- readline-8.2/nls.c.orig	2022-11-22 18:41:48.302144300 +0100
+++ readline-8.2/nls.c	2022-12-03 18:37:54.991412600 +0100
@@ -49,6 +49,11 @@
 
 #include <ctype.h>
 
+#if defined (_WIN32)
+#  include <windows.h>
+#  include <versionhelpers.h>
+#endif
+
 #include "rldefs.h"
 #include "readline.h"
 #include "rlshell.h"
@@ -109,7 +114,11 @@
   char *cp;
   size_t len;
 
-#if HAVE_LANGINFO_CODESET
+#if defined (_WIN32)
+  /* On Windows, the relevant "locale" is the selected codepage of the used
+     console. */
+  return (IsWindows7OrGreater () && (GetConsoleCP () == 65001));
+#elif HAVE_LANGINFO_CODESET
   cp = nl_langinfo (CODESET);
   return (STREQ (cp, "UTF-8") || STREQ (cp, "utf8"));
 #else
@@ -138,11 +147,18 @@
 #if defined (HAVE_SETLOCALE)
   if (lspec == 0 || *lspec == 0)
     lspec = setlocale (LC_CTYPE, (char *)NULL);
+#if defined (_WIN32)
+  /* Setting an UTF-8 locale is not a no-op on Windows.  Instead the
+     information about the locale is lost.  Use whatever we got at this
+     point. */
+  ret = lspec;
+#else
   if (lspec == 0)
     lspec = "";
   ret = setlocale (LC_CTYPE, lspec);	/* ok, since it does not change locale */
   if (ret == 0 || *ret == 0)
     ret = setlocale (LC_CTYPE, (char *)NULL);
+#endif
   if (ret == 0 || *ret == 0)
     ret = RL_DEFAULT_LOCALE;
 #else