bug-coreutils
[Top][All Lists]
Advanced

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

POSIX requires checking all *printf return values?!?


From: Jim Meyering
Subject: POSIX requires checking all *printf return values?!?
Date: Fri, 19 Oct 2007 17:08:09 +0200

Andreas Schwab <address@hidden> wrote:
> Jim Meyering <address@hidden> writes:
>
>> Could it be a bug in printf for failing, yet not setting the
>> stream-failure indicator that is checked by close_stdout's ferror?
>
> A failure from printf does not necessarily mean an output failure.  It
> can also be ENOMEM or EILSEQ, which are unrelated to output.

I've been looking at the standard to see where it specifies this.
While the fwrite description is quite clear that the "error indicator"
is set for write errors, the section describing printf and fprintf:

  http://www.opengroup.org/onlinepubs/000095399/functions/printf.html

doesn't even mention the error indicator.  Not directly, anyway.
However, it *does* refer to fputc for error conditions.
The description of fputc clearly states that upon error, it *shall* set
the error indicator, and that it may fail if ENOMEM:

    RETURN VALUE
    Upon successful completion, fputc() shall return the value it has
    written. Otherwise, it shall return EOF, the error indicator for the
    stream shall be set, and errno shall be set to indicate the error.

    ERRORS
    ...
    The fputc( )   function may fail if:
    [ENOMEM]

I'm beginning to wonder if this is an error in the C library after all.
Surely POSIX doesn't intend to require that all programs test every
*printf return value.  That would be silly.  If so, what's the point
of the stream error indicator?




reply via email to

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