Unfortunately I had some trouble using that patch with GNU Emacs, which
wants to avoid bringing in a lot of Gnulib code for various reasons. The
trouble is that this change to nstrftime brings in the hard-locale
module, which brings in a bunch of other stuff.
To remove this dependency I installed the attached patch, which takes a
stab at fixing the MS-Windows %c problem in a different way. I hope it's
good enough. If not, perhaps on MS-Windows nstrftime can test whether
it's a hard locale by invoking the underlying strftime with a %B for
tm_mon==4 and see whether that generates "May". Or something like that.From 66de6c8f05c0207c16581f2a5f1c2796868ba51b Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Mon, 3 Jun 2024 22:00:59 -0700
Subject: [PATCH] nstrftime: remove dependency on hard-locale
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
GNU Emacs would rather keep dependencies to a minimum,
and hard-locale brings in some other stuff.
* lib/strftime.c: Include locale.h only if (USE_C_LOCALE &&
HAVE_STRFTIME_L) || ((defined __NetBSD__ || defined __sun) &&
REQUIRE_GNUISH_STRFTIME_AM_PM). Do not include hard-locale.h.
(libc_hidden_def): On native MS-Windows, use the C locale %c
format regardless of language. I hope that’s good enough.
If not, let’s try to think of a way of solving the problem
that doesn’t require using hard_locale.
* modules/nstrftime (Depends-on): Remove hard-locale.
* modules/nstrftime-tests (test_nstrftime_LDADD):
Remove $(HARD_LOCALE_LIB).
* tests/test-nstrftime.h (locales_test):
Add a test that I hope works on French MS-Windows.
---
ChangeLog | 18 ++++++++++++++++++
lib/strftime.c | 14 ++++++--------
modules/nstrftime | 1 -
modules/nstrftime-tests | 2 +-
tests/test-nstrftime.h | 1 +
5 files changed, 26 insertions(+), 10 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index bd38e2a79d..787edff23d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2024-06-03 Paul Eggert <egg...@cs.ucla.edu>
+
+ nstrftime: remove dependency on hard-locale
+ GNU Emacs would rather keep dependencies to a minimum,
+ and hard-locale brings in some other stuff.
+ * lib/strftime.c: Include locale.h only if (USE_C_LOCALE &&
+ HAVE_STRFTIME_L) || ((defined __NetBSD__ || defined __sun) &&
+ REQUIRE_GNUISH_STRFTIME_AM_PM). Do not include hard-locale.h.
+ (libc_hidden_def): On native MS-Windows, use the C locale %c
+ format regardless of language. I hope that’s good enough.
+ If not, let’s try to think of a way of solving the problem
+ that doesn’t require using hard_locale.
+ * modules/nstrftime (Depends-on): Remove hard-locale.
+ * modules/nstrftime-tests (test_nstrftime_LDADD):
+ Remove $(HARD_LOCALE_LIB).
+ * tests/test-nstrftime.h (locales_test):
+ Add a test that I hope works on French MS-Windows.
+
2024-06-03 Paul Eggert <egg...@cs.ucla.edu>
ieee754-h: port to Android NDK r26
diff --git a/lib/strftime.c b/lib/strftime.c
index 8eeea45ef4..5f1e76833f 100644
--- a/lib/strftime.c
+++ b/lib/strftime.c
@@ -92,13 +92,14 @@ extern char *tzname[];
#include <stdlib.h>
#include <string.h>
-#include <locale.h>
+#if USE_C_LOCALE && HAVE_STRFTIME_L
+# include <locale.h>
+#endif
+
#if (defined __NetBSD__ || defined __sun) && REQUIRE_GNUISH_STRFTIME_AM_PM
+# include <locale.h>
# include "localename.h"
#endif
-#if !USE_C_LOCALE
-# include "hard-locale.h"
-#endif
#include "attribute.h"
#include <intprops.h>
@@ -1292,10 +1293,7 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize)
subfmt = L_("%a %b %e %H:%M:%S %Y");
#elif defined _WIN32 && !defined __CYGWIN__
/* On native Windows, "%c" is "%d/%m/%Y %H:%M:%S" by default. */
- if (hard_locale (LC_TIME))
- subfmt = L_("%a %e %b %Y %H:%M:%S");
- else
- subfmt = L_("%a %b %e %H:%M:%S %Y");
+ subfmt = L_("%a %b %e %H:%M:%S %Y");
#else
goto underlying_strftime;
#endif
diff --git a/modules/nstrftime b/modules/nstrftime
index a9e86fb1f8..e2f852a16b 100644
--- a/modules/nstrftime
+++ b/modules/nstrftime
@@ -14,7 +14,6 @@ c99
errno
extensions
intprops
-hard-locale
libc-config
localename-unsafe-limited
stdbool
diff --git a/modules/nstrftime-tests b/modules/nstrftime-tests
index 40ea1bd199..b5c6ac2fa5 100644
--- a/modules/nstrftime-tests
+++ b/modules/nstrftime-tests
@@ -26,4 +26,4 @@ TESTS_ENVIRONMENT += \
LOCALE_FR='@LOCALE_FR@' \
LOCALE_FR_UTF8='@LOCALE_FR_UTF8@'
check_PROGRAMS += test-nstrftime
-test_nstrftime_LDADD = $(LDADD) $(SETLOCALE_LIB) $(HARD_LOCALE_LIB)
+test_nstrftime_LDADD = $(LDADD) $(SETLOCALE_LIB)
diff --git a/tests/test-nstrftime.h b/tests/test-nstrftime.h
index b822f3acd1..80edc7aaec 100644
--- a/tests/test-nstrftime.h
+++ b/tests/test-nstrftime.h
@@ -482,6 +482,7 @@ locales_test (language_t language)
ASSERT (STREQ (buf, "jeu. 26 oct. 2017 06:40:03") /* glibc, Cygwin */
|| STREQ (buf, "jeu. 26 oct. 06:40:03 2017") /* FreeBSD */
|| STREQ (buf, "Jeu 26 oct 06:40:03 2017") /* macOS, older FreeBSD */
+ || STREQ (buf, "Jeu oct. 26 06:40:03 2017") /* MS-Windows */
|| STREQ (buf, "26 octobre 2017 06:40:03") /* NetBSD */
|| STREQ (buf, "26 octobre 2017 à 06:40:03") /* Solaris (UTF-8) */
|| STREQ (buf, "26 octobre 2017 \340 06:40:03") /* Solaris (ISO-8859-1) */);
--
2.43.0