* NEWS: Mention this, and coalesce recent changes for the
benefit of future readers.
* lib/strftime.c (__strftime_internal):
Preserve errno only if FAILURE == 0,
for consistency with other functions returning -1 on failure.
---
 ChangeLog      |  9 +++++++++
 NEWS           | 13 +++++--------
 lib/strftime.c |  6 +++++-
 lib/strftime.h |  5 +++--
 4 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index bf7345152d..f4fbb6f1fa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2025-11-01  Paul Eggert  <[email protected]>
+
+       nstrftime: do not preserve errno on success
+       * NEWS: Mention this, and coalesce recent changes for the
+       benefit of future readers.
+       * lib/strftime.c (__strftime_internal):
+       Preserve errno only if FAILURE == 0,
+       for consistency with other functions returning -1 on failure.
+
 2025-11-01  Bruno Haible  <[email protected]>
 
        openat2 tests: Avoid test failure on native Windows.
diff --git a/NEWS b/NEWS
index 0f226108ca..d954840bfa 100644
--- a/NEWS
+++ b/NEWS
@@ -78,14 +78,11 @@ User visible incompatible changes
 
 Date        Modules         Changes
 
-2025-10-31  nstrftime       The return type changed from size_t to ptrdiff_t.
-            c-nstrftime     The return value in case of failure changed from 0
-                            to -1.
-
-2025-10-31  fprintftime     The return value in case of failure changed from 0
-                            to -1.
-
-2025-10-30  fprintftime     The return value is changed from size_t to off64_t.
+2025-11-01  nstrftime       The return type is now signed not size_t,
+            c-nstrftime     the failure return value is now -1 not 0,
+            fprintftime     and errno is no longer preserved on success.
+                            The return type is now off64_t for fprintftime,
+                            ptrdiff_t for the others.
 
 2025-08-05  git-merge-changelog  This module is removed.  Use the package from
                             https://git.savannah.gnu.org/git/vc-changelog.git
diff --git a/lib/strftime.c b/lib/strftime.c
index a78b9b8cef..35ec5e4fc4 100644
--- a/lib/strftime.c
+++ b/lib/strftime.c
@@ -1182,7 +1182,8 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG 
(size_t maxsize)
 #endif
 #if FPRINTFTIME
   byte_count_t maxsize = SBYTE_COUNT_MAX;
-#else
+#endif
+#if FAILURE == 0
   int saved_errno = errno;
 #endif
 
@@ -2398,6 +2399,9 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG 
(size_t maxsize)
 #if ! FPRINTFTIME
   if (p && maxsize != 0)
     *p = L_('\0');
+#endif
+
+#if FAILURE == 0
   errno = saved_errno;
 #endif
 
diff --git a/lib/strftime.h b/lib/strftime.h
index 0ac129a499..e444a63baa 100644
--- a/lib/strftime.h
+++ b/lib/strftime.h
@@ -71,14 +71,15 @@ extern "C" {
 
    Store the result, as a string with a trailing NUL character, at the
    beginning of the array __S[0..__MAXSIZE-1] and return the length of
-   that string, not counting the trailing NUL, and without changing errno.
+   that string, not counting the trailing NUL.
    If unsuccessful, possibly change the array __S, set errno, and return -1;
    errno == ERANGE means the string didn't fit.
 
    This function is like strftime, but with two more arguments:
      * __TZ instead of the local timezone information,
      * __NS as the number of nanoseconds in the %N directive,
-   and with a failure return value of -1 instead of 0.
+   and on success it does not preserve errno,
+   and on failure it returns -1 not 0.
  */
 ptrdiff_t nstrftime (char *restrict __s, size_t __maxsize,
                      char const *__format,
-- 
2.51.0


Reply via email to