In the recent addition of non-Gregorian calendars to module 'nstrftime',
I tried to minimize the module dependencies, for the sake of Emacs
(which doesn't like 'threadlib').
But it turns out that this is not ideal:
- With this approach, non-Gregorian calendars are not supported on
OpenBSD, AIX, Android.
- The coreutils test suite would need to special-case these three
operating systems.
Collin Funk noted that coreutils already contains these dependencies.
So, what is ideal for Emacs is not ideal for coreutils.
This patch makes the 'nstrftime' module work better for coreutils,
and adds a module 'nstrftime-limited' that is meant for Emacs.
Paul, the right action now is to replace 'nstrftime' with 'nstrftime-limited'
in the Emacs gnulib configuration.
Collin: With this patch, the three coreutils tests now fail on OpenBSD the same
way as they fail on macOS <https://debbugs.gnu.org/cgi/bugreport.cgi?bug=79118>.
This means, you can use gdb on OpenBSD to debug it.
2025-07-29 Bruno Haible <[email protected]>
nstrftime: Handle non-Gregorian calendars the same way on all platforms.
Suggested by Collin Funk.
* modules/nstrftime-limited: New file, based on modules/nstrftime.
* modules/nstrftime (Depends-on): Add nstrftime-limited.
Add localename-unsafe. Remove localename-unsafe-limited.
(configure.ac): Invoke gl_MODULE_INDICATOR.
(Makefile.am): Don't add nstrftime.c to lib_SOURCES; this would conflict
with modules/nstrftime-limited.
(Link): Add $(LIBTHREAD).
* lib/strftime.c (SUPPORT_NON_GREG_CALENDARS_IN_STRFTIME): Don't force
to false if GNULIB_NSTRFTIME is defined.
* modules/nstrftime-tests (Makefile.am): Link test-nstrftime,
test-nstrftime-?? with $(LIBTHREAD).
diff --git a/lib/strftime.c b/lib/strftime.c
index 6495a6847e..537172d8be 100644
--- a/lib/strftime.c
+++ b/lib/strftime.c
@@ -76,7 +76,8 @@
# define SUPPORT_NON_GREG_CALENDARS_IN_STRFTIME true
#endif
#if defined _LIBC || (HAVE_ONLY_C_LOCALE || USE_C_LOCALE) \
- || (defined __OpenBSD__ || defined _AIX || defined __ANDROID__)
+ || ((defined __OpenBSD__ || defined _AIX || defined __ANDROID__) \
+ && !GNULIB_NSTRFTIME)
# undef SUPPORT_NON_GREG_CALENDARS_IN_STRFTIME
# define SUPPORT_NON_GREG_CALENDARS_IN_STRFTIME false
#endif
diff --git a/modules/nstrftime b/modules/nstrftime
index c61fb1e84a..aa1740ebc4 100644
--- a/modules/nstrftime
+++ b/modules/nstrftime
@@ -13,6 +13,7 @@ m4/nstrftime.m4
m4/tm_gmtoff.m4
Depends-on:
+nstrftime-limited
attribute
c-ctype
c99
@@ -21,22 +22,23 @@ extensions
intprops
libc-config
localcharset
-localename-unsafe-limited
+localename-unsafe
bool
stdckdint-h
time_rz
configure.ac:
gl_FUNC_GNU_STRFTIME
+gl_MODULE_INDICATOR([nstrftime])
Makefile.am:
-lib_SOURCES += nstrftime.c
Include:
"strftime.h"
Link:
@INTL_MACOSX_LIBS@
+$(LIBTHREAD)
License:
LGPL
diff --git a/modules/nstrftime-limited b/modules/nstrftime-limited
new file mode 100644
index 0000000000..9f53b621a7
--- /dev/null
+++ b/modules/nstrftime-limited
@@ -0,0 +1,47 @@
+Description:
+nstrftime() function: convert date and time to string, with GNU extensions.
+Supports non-Gregorian calendars on a limited set of platforms:
+all except OpenBSD, AIX, Android.
+
+Files:
+lib/strftime.h
+lib/nstrftime.c
+lib/strftime.c
+lib/calendars.h
+lib/calendar-thai.h
+lib/calendar-persian.h
+lib/calendar-ethiopian.h
+m4/nstrftime.m4
+m4/tm_gmtoff.m4
+
+Depends-on:
+attribute
+c-ctype
+c99
+errno-h
+extensions
+intprops
+libc-config
+localcharset
+localename-unsafe-limited
+bool
+stdckdint-h
+time_rz
+
+configure.ac:
+gl_FUNC_GNU_STRFTIME
+
+Makefile.am:
+lib_SOURCES += nstrftime.c
+
+Include:
+"strftime.h"
+
+Link:
+@INTL_MACOSX_LIBS@
+
+License:
+LGPL
+
+Maintainer:
+Jim Meyering, glibc
diff --git a/modules/nstrftime-tests b/modules/nstrftime-tests
index 91c21edf77..addd304933 100644
--- a/modules/nstrftime-tests
+++ b/modules/nstrftime-tests
@@ -43,8 +43,8 @@ check_PROGRAMS += \
test-nstrftime-TH \
test-nstrftime-IR \
test-nstrftime-ET
-test_nstrftime_LDADD = $(LDADD) $(SETLOCALE_LIB) @INTL_MACOSX_LIBS@
-test_nstrftime_DE_LDADD = $(LDADD) $(SETLOCALE_LIB) @INTL_MACOSX_LIBS@
-test_nstrftime_TH_LDADD = $(LDADD) $(SETLOCALE_LIB) @INTL_MACOSX_LIBS@
-test_nstrftime_IR_LDADD = $(LDADD) $(SETLOCALE_LIB) @INTL_MACOSX_LIBS@
-test_nstrftime_ET_LDADD = $(LDADD) $(SETLOCALE_LIB) @INTL_MACOSX_LIBS@
+test_nstrftime_LDADD = $(LDADD) $(SETLOCALE_LIB) @INTL_MACOSX_LIBS@
$(LIBTHREAD)
+test_nstrftime_DE_LDADD = $(LDADD) $(SETLOCALE_LIB) @INTL_MACOSX_LIBS@
$(LIBTHREAD)
+test_nstrftime_TH_LDADD = $(LDADD) $(SETLOCALE_LIB) @INTL_MACOSX_LIBS@
$(LIBTHREAD)
+test_nstrftime_IR_LDADD = $(LDADD) $(SETLOCALE_LIB) @INTL_MACOSX_LIBS@
$(LIBTHREAD)
+test_nstrftime_ET_LDADD = $(LDADD) $(SETLOCALE_LIB) @INTL_MACOSX_LIBS@
$(LIBTHREAD)