From 0e5d4c8bc02ea8615e43cae70a9fc114eabcf778 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 18 Jun 2024 14:27:18 +0200 Subject: [PATCH] c-nstrftime: Fix warning on platforms without strftime_l. * lib/strftime.c: Add comment regarding HAVE_STRFTIME_L. (underlying_strftime): Don't define if this function is not used. Correct indentation. Simplify #if condition. (__strftime_internal): Disable code that is not used on platforms without strftime_l. --- ChangeLog | 9 +++++++++ lib/strftime.c | 22 +++++++++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 75f06623d6..cb44449076 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2024-06-18 Bruno Haible + + c-nstrftime: Fix warning on platforms without strftime_l. + * lib/strftime.c: Add comment regarding HAVE_STRFTIME_L. + (underlying_strftime): Don't define if this function is not used. + Correct indentation. Simplify #if condition. + (__strftime_internal): Disable code that is not used on platforms + without strftime_l. + 2024-06-17 Paul Eggert Improve wording for Y2038 and largefile probes diff --git a/lib/strftime.c b/lib/strftime.c index ff52fc8119..a757b4f313 100644 --- a/lib/strftime.c +++ b/lib/strftime.c @@ -38,8 +38,6 @@ # include "time-internal.h" #endif -#define HAVE_NATIVE_TIME_Z (USE_C_LOCALE ? HAVE_STRFTIME_LZ : HAVE_STRFTIME_Z) - /* Whether to require GNU behavior for AM and PM indicators, even on other platforms. This matters only in non-C locales. The default is to require it; you can override this via @@ -377,6 +375,15 @@ memcpy_uppcase (CHAR_T *dest, const CHAR_T *src, size_t len LOCALE_PARAM) #endif +/* Note: We assume that HAVE_STRFTIME_LZ implies HAVE_STRFTIME_L. + Otherwise, we would have to write (HAVE_STRFTIME_L || HAVE_STRFTIME_LZ) + instead of HAVE_STRFTIME_L everywhere. */ + +/* Define to 1 if we can use the system's native functions that takes a + timezone_t argument. As of 2024, this is only true on NetBSD. */ +#define HAVE_NATIVE_TIME_Z \ + (USE_C_LOCALE && HAVE_STRFTIME_L ? HAVE_STRFTIME_LZ : HAVE_STRFTIME_Z) + #if USE_C_LOCALE && HAVE_STRFTIME_L /* Cache for the C locale object. @@ -837,7 +844,8 @@ static size_t __strftime_internal (STREAM_OR_CHAR_T *, STRFTIME_ARG (size_t) bool, enum pad_style, int, bool * extra_args_spec LOCALE_PARAM); -#ifndef _LIBC +#if !defined _LIBC \ + && (!(USE_C_LOCALE && !HAVE_STRFTIME_L) || !HAVE_STRUCT_TM_TM_ZONE) /* Make sure we're calling the actual underlying strftime. In some cases, time.h contains something like @@ -869,17 +877,17 @@ underlying_strftime (timezone_t tz, char *ubuf, size_t ubufsize, *u++ = format_char; *u = '\0'; -#if !HAVE_NATIVE_TIME_Z +# if !HAVE_NATIVE_TIME_Z if (tz && tz != local_tz) { tz = set_tz (tz); if (!tz) return 0; } -#endif +# endif size_t len; -# if USE_C_LOCALE && (HAVE_STRFTIME_L || HAVE_STRFTIME_LZ) +# if USE_C_LOCALE && HAVE_STRFTIME_L locale_t locale = c_locale (); if (!locale) return 0; /* errno is set here */ @@ -1467,7 +1475,7 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize) } break; -#ifndef _LIBC +#if !defined _LIBC && !(USE_C_LOCALE && !HAVE_STRFTIME_L) underlying_strftime: { char ubuf[1024]; /* enough for any single format in practice */ -- 2.39.5