bug-gnulib
[Top][All Lists]
Advanced

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

nstrtime, c-nstrftime: Fix %c directive's result on glibc ≤ 2.30


From: Bruno Haible
Subject: nstrtime, c-nstrftime: Fix %c directive's result on glibc ≤ 2.30
Date: Sun, 24 Mar 2024 19:25:50 +0100

On 2024-02-08 I did:

        nstrtime, c-nstrftime: Fix %c directive's result on NetBSD, Solaris.
        * lib/strftime.c (__strftime_internal): On NetBSD and Solaris, remove
        the last word of the %c directive's result if it looks like a time zone.
        * doc/posix-functions/strftime.texi: Mention this as a restriction of
        strftime.

The nstrftime unit test for %c also fails on glibc versions ≤ 2.30 (Fedora 31,
Fedora 30, CentOS 8 Stream, etc.). This patch provides a workaround.


2024-03-24  Bruno Haible  <bruno@clisp.org>

        nstrtime, c-nstrftime: Fix %c directive's result on glibc ≤ 2.30.
        * lib/strftime.c (__strftime_internal): On glibc ≤ 2.30, like on NetBSD
        and Solaris, remove the last word of the %c directive's result if it
        looks like a time zone.
        * doc/posix-functions/strftime.texi: Update platforms list.

diff --git a/doc/posix-functions/strftime.texi 
b/doc/posix-functions/strftime.texi
index 1edd08e7f0..4bbfbabec7 100644
--- a/doc/posix-functions/strftime.texi
+++ b/doc/posix-functions/strftime.texi
@@ -19,7 +19,7 @@
 The %c specifier does not work with a time retrieved through @code{gmtime}
 or @code{gmtime_r}, since it outputs also the current time zone,
 on some platforms:
-NetBSD 9.3, Solaris 11.4.
+glibc 2.30, NetBSD 9.3, Solaris 11.4.
 @item
 The %r specifier produces empty output, at least in a French locale,
 on some platforms:
diff --git a/lib/strftime.c b/lib/strftime.c
index 128176cad4..684d910771 100644
--- a/lib/strftime.c
+++ b/lib/strftime.c
@@ -1336,7 +1336,7 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG 
(size_t maxsize)
 # endif
             if (len != 0)
               {
-# if defined __NetBSD__ || defined __sun /* NetBSD, Solaris */
+# if (__GLIBC__ == 2 && __GLIBC_MINOR__ < 31) || defined __NetBSD__ || defined 
__sun /* glibc < 2.31, NetBSD, Solaris */
                 if (format_char == L_('c'))
                   {
                     /* The output of the strftime %c directive consists of the
@@ -1374,7 +1374,7 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG 
(size_t maxsize)
                           }
                       }
                   }
-#  if REQUIRE_GNUISH_STRFTIME_AM_PM
+#  if (defined __NetBSD__ || defined __sun) && REQUIRE_GNUISH_STRFTIME_AM_PM
                 /* The output of the strftime %p and %r directives contains
                    an AM/PM indicator even for locales where it is not
                    suitable, such as French.  Remove this indicator.  */






reply via email to

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