Paul Eggert wrote:
> +       int _r = fputc (Byte, P); \
> +       if (_r < 0) \
> +         return _r; \

When fputc fails, it returns EOF, which POSIX [1] guarantees to be negative.
But in fprintftime.h we make the stronger assertion that the return value
is == -1, not only negative. (Although, admittedly, all existing platforms
define EOF to -1 or (-1).)

[1] https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdio.h.html


2025-11-01  Bruno Haible  <[email protected]>

        fprintftime: Return -1 on output error.
        * lib/strftime.c (FPUTC): On failure, return FAILURE, not EOF.
        (width_cpy) [FPRINTFTIME]: Write -1 as FAILURE, for consistency.

diff --git a/lib/strftime.c b/lib/strftime.c
index f18e8f65cd..41e7c5477c 100644
--- a/lib/strftime.c
+++ b/lib/strftime.c
@@ -234,7 +234,7 @@ typedef sbyte_count_t retval_t;
      { \
        int _r = fputc (Byte, P); \
        if (_r < 0) \
-         return _r; \
+         return FAILURE; \
      } \
    while (false)
 
@@ -308,7 +308,7 @@ typedef sbyte_count_t retval_t;
            for (byte_count_t _i = 0; _i < _n; _i++)                           \
              FPUTC (TOUPPER ((UCHAR_T) _s[_i], loc), p);                      \
          else if (fwrite (_s, _n, 1, p) == 0)                                 \
-           return -1;                                                         \
+           return FAILURE;                                                    \
        }                                                                      \
      while (0)                                                                \
     )




Reply via email to