]> Savannah Git Hosting - gnulib.git/commitdiff
nstrftime: Work around strftime bug with %r on macOS and FreeBSD.
authorBruno Haible <bruno@clisp.org>
Wed, 7 Feb 2024 22:34:28 +0000 (23:34 +0100)
committerBruno Haible <bruno@clisp.org>
Wed, 7 Feb 2024 22:43:10 +0000 (23:43 +0100)
* lib/strftime.c (__strftime_internal): For %r, don't use the underlying
strftime() directly.
* doc/posix-functions/strftime.texi: Mention the %r bug.

ChangeLog
doc/posix-functions/strftime.texi
lib/strftime.c

index 617b4dde10644643ad17c75457570966ad28182c..00ac5424a745c7fc9449188f2344f4d34b30e8cc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-02-07  Bruno Haible  <bruno@clisp.org>
+
+       nstrftime: Work around strftime bug with %r on macOS and FreeBSD.
+       * lib/strftime.c (__strftime_internal): For %r, don't use the underlying
+       strftime() directly.
+       * doc/posix-functions/strftime.texi: Mention the %r bug.
+
 2024-02-07  Paul Eggert  <eggert@cs.ucla.edu>
 
        Assume ‘long long’ support
index 13605c24c22cc36512037bdc3d170bda7e1cac0a..7c4c0391fa07880044d26c3d3662f43afdfea955 100644 (file)
@@ -16,6 +16,10 @@ when the environment variable @code{TZ} has been set by Cygwin.
 Portability problems not fixed by Gnulib:
 @itemize
 @item
+The %r specifier produces empty output, at least in a French locale,
+on some platforms:
+macOS 12.5, FreeBSD 14.0.
+@item
 The Windows C runtime library (which is used by MinGW) does not
 support the %e specifier (and possibly the other more recent SUS
 specifiers too, i.e., %C, %D, %h, %n, %r, %R, %t, and %T).
index bd519e36abb9b590f19b2a116869b6a0a356a018..d81c7eddfaf6d2ff5bd28417cd5429d489100a5d 100644 (file)
@@ -1168,6 +1168,10 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize)
               == L_('\0'))
             subfmt = L_("%I:%M:%S %p");
           goto subformat;
+#elif (defined __APPLE__ && defined __MACH__) || defined __FreeBSD__
+          /* macOS, FreeBSD strftime() may produce empty output for "%r".  */
+          subfmt = L_("%I:%M:%S %p");
+          goto subformat;
 #else
           goto underlying_strftime;
 #endif