-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 According to Karl Berry on 1/24/2009 5:10 PM: > printf can fail for reasons like ENOMEM which do not set the ferror > flag and thus are not caught by the close_stdout atexit module, so a > robust program should be checking for failures. > > Whoa. I hadn't seen this before. at_exit is not sufficient to check > for write errors?
For write errors, yes. But for other formatting errors (EILSEQ, ENOMEM), no, because nothing was written to the stream, so there is no reason for the stream error indicator to be set. In particular, this very question on the Austin mailing list (the POSIX folks) admitted that printf is less robust than fputc: https://www.opengroup.org/sophocles/show_mail.tpl?CALLER=show_archive.tpl&source=L&listname=austin-group-l&id=11114 > What does this mean? We don't get to ever use printf? That's why Jim invented the xprintf module: http://thread.gmane.org/gmane.comp.gnu.coreutils.bugs/11611/focus=11620 http://thread.gmane.org/gmane.comp.lib.gnulib.bugs/11664/focus=11730 > (Well, if we want to be "robust", but of course we do.) This seems crazy! It's a one-character addition (plus a gnulib module) to use xprintf everywhere you used to use printf; and it is no worse than using xmalloc instead of malloc. - -- Don't work too hard, make some time for fun as well! Eric Blake e...@byu.net -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (Cygwin) Comment: Public key at home.comcast.net/~ericblake/eblake.gpg Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkl7tLcACgkQ84KuGfSFAYAynwCgupja5wMUDvlHzLb5WYowaftZ SaQAn3boSMqA1AH6MSKDU/Bma/rHEtYG =rvXt -----END PGP SIGNATURE-----