This raises an interesting question: is there any IO function that should return unit/void? Or equivalently are there any IO functions for which we can safely ignore the return value/ignore all exceptions? It seems like every single IO thing I can think of can have a relevant error, regardless of whether it's file-system related, network, or anything else.
if (fflush(stdout) != 0 || ferror(stdout) != 0)
{
perror("stdout");
return EXIT_FAILURE;
}
at the end of the program. The same should be done for stderr as well.In GNU programs you can use atexit(close_stdout) to do this automatically.