bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

nstrftime: Work around strftime bug with %r on macOS and FreeBSD


From: Bruno Haible
Subject: nstrftime: Work around strftime bug with %r on macOS and FreeBSD
Date: Wed, 07 Feb 2024 23:39:20 +0100

On macOS 12.5 and FreeBSD 14.0, the %r directive of strftime produces no
output at all in a French locale. This is certainly not what users who
read POSIX [1] expect.
[1] https://pubs.opengroup.org/onlinepubs/9699919799/functions/strftime.html

And nstrftime inherits this bug from the system's strftime() implementation.

This patch adds a workaround in the nstrftime function.


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.

diff --git a/doc/posix-functions/strftime.texi 
b/doc/posix-functions/strftime.texi
index 13605c24c2..7c4c0391fa 100644
--- a/doc/posix-functions/strftime.texi
+++ b/doc/posix-functions/strftime.texi
@@ -16,6 +16,10 @@
 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).
diff --git a/lib/strftime.c b/lib/strftime.c
index bd519e36ab..d81c7eddfa 100644
--- a/lib/strftime.c
+++ b/lib/strftime.c
@@ -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






reply via email to

[Prev in Thread] Current Thread [Next in Thread]