]> Savannah Git Hosting - gnulib.git/commitdiff
nstrftime: don’t assume <locale.h>
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 5 Jun 2024 15:27:55 +0000 (08:27 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 5 Jun 2024 15:28:51 +0000 (08:28 -0700)
* lib/strftime.c: Include <locale.h> only if needed, since Emacs
attempts to be portable to platforms lacking <locale.h> so it
avoids localename-unsafe-limited and defines
REQUIRE_GNUISH_STRFTIME_AM_PM to false.

ChangeLog
lib/strftime.c

index d04105378dc81c6071385853b16e00597c3ef45a..155fd88a054e9720d394389ee7461fa09a6d2dc9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-06-05  Paul Eggert  <eggert@cs.ucla.edu>
+
+       nstrftime: don’t assume <locale.h>
+       * lib/strftime.c: Include <locale.h> only if needed, since Emacs
+       attempts to be portable to platforms lacking <locale.h> so it
+       avoids localename-unsafe-limited and defines
+       REQUIRE_GNUISH_STRFTIME_AM_PM to false.
+
 2024-06-05  Bruno Haible  <bruno@clisp.org>
 
        nstrftime: Make %c work on native Windows again.
index 19a2d73ebd8a4b56b52671a9db254d5af4e610f9..4441584121aa20cb306828ae5f8ef8d7dba5b26d 100644 (file)
@@ -92,7 +92,12 @@ extern char *tzname[];
 #include <stdlib.h>
 #include <string.h>
 
-#include <locale.h>
+#if (((defined __NetBSD__ || defined __sun) && REQUIRE_GNUISH_STRFTIME_AM_PM) \
+     || (defined _WIN32 && !defined __CYGWIN__) \
+     || (USE_C_LOCALE && HAVE_STRFTIME_L))
+# include <locale.h>
+#endif
+
 #if (defined __NetBSD__ || defined __sun) && REQUIRE_GNUISH_STRFTIME_AM_PM
 # include "localename.h"
 #elif defined _WIN32 && !defined __CYGWIN__
@@ -1727,7 +1732,8 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize)
 #elif USE_C_LOCALE && !HAVE_STRFTIME_L
           subfmt = L_("%I:%M:%S %p");
           goto subformat;
-#elif (defined __APPLE__ && defined __MACH__) || defined __FreeBSD__ || (defined _WIN32 && !defined __CYGWIN__)
+#elif ((defined __APPLE__ && defined __MACH__) || defined __FreeBSD__ \
+       || (defined _WIN32 && !defined __CYGWIN__))
           /* macOS, FreeBSD, native Windows strftime() may produce empty output
              for "%r".  */
           subfmt = L_("%I:%M:%S %p");