Search code examples
cioprintferrno

Does printf() set errno upon failure?


Does printf() set errno to an appropriate value apart from just returning 'a negative value' upon failure ?

I can't seem to find man pages that say anything about this on Google .

Close this question if it's a duplicate. Link the answer .


Solution

  • Yes it does, on any POSIX system, but not necessarily in any ISO C implementation.

    From https://pubs.opengroup.org/onlinepubs/9699919799/functions/fprintf.html:

    If an output error was encountered, these functions shall return a negative value and set errno to indicate the error.

    The bolded part is marked as an extension to ISO C.