This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Checking for errors on stdout/stderr


Robust programs need to check for errors when writing stdout/stderr, and
exit with an error status if they occur.  (For example, stdout might be
redirected onto a full disk, but stderr or the exit status might still be
looked at.)  At present, programs in GCC do not do this, as shown for
example by "gcc --help >/dev/full".  Some other GNU programs, such as 
"ls", do properly detect such errors.

Unless you check all calls to output functions, this check needs to be
made by flushing or closing the appropriate streams at exit, and checking
for errors on them.  This does, however, mean that the value of errno in
such a case may not be meaningful, since it may have changed since the
actual error occurred.

Should such checks be inserted in all GCC programs, or should they go in
xexit in libiberty and all GCC programs be made to use xexit?  Should an
error message involving the standard error text for errno be printed (if
the error occurs with stdout but stderr may be OK), even though errno
might not be relevant?  Or should all programs use checking versions of
the output functions rather than just calling printf, etc., or check every
return from printf, etc., to get reliable error detection as soon as the
error occurs?

-- 
Joseph S. Myers
jsm28@cam.ac.uk


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]