From 44a6681ba834fb575828e3864d4c21d3a7e2410e Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Wed, 7 Feb 2024 23:34:28 +0100 Subject: [PATCH] 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. --- ChangeLog | 7 +++++++ doc/posix-functions/strftime.texi | 4 ++++ lib/strftime.c | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/ChangeLog b/ChangeLog index 617b4dde10..00ac5424a7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2024-02-07 Bruno Haible + + 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 Assume ‘long long’ support 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 @@ 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). 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 -- 2.39.5