* lib/strftime.c (__strftime_internal) [FPRINTFTIME]:
Do not restore errno if there is no error,
as the API does not promise this.
---
 ChangeLog      | 7 +++++++
 lib/strftime.c | 6 +++---
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 055b124247..aaedd7a74c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2025-10-31  Paul Eggert  <[email protected]>
+
+       fprintftime: omit unnecessary errno restore
+       * lib/strftime.c (__strftime_internal) [FPRINTFTIME]:
+       Do not restore errno if there is no error,
+       as the API does not promise this.
+
 2025-10-31  Bruno Haible  <[email protected]>
 
        posix_spawn_file_actions_addclose: Ignore test failure on NetBSD 10.0.
diff --git a/lib/strftime.c b/lib/strftime.c
index afb783778e..2d8eda5622 100644
--- a/lib/strftime.c
+++ b/lib/strftime.c
@@ -1199,9 +1199,9 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG 
(size_t maxsize)
 #endif
 #if FPRINTFTIME
   byte_count_t maxsize = SBYTE_COUNT_MAX;
-#endif
-
+#else
   int saved_errno = errno;
+#endif
 
 #ifdef _NL_CURRENT
   /* We cannot make the following values variables since we must delay
@@ -2415,8 +2415,8 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG 
(size_t maxsize)
 #if ! FPRINTFTIME
   if (p && maxsize != 0)
     *p = L_('\0');
+  errno = saved_errno;
 #endif
 
-  errno = saved_errno;
   return i;
 }
-- 
2.51.0


Reply via email to