X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fclose-stream.c;h=8819b58095df490d8786696439b8ee871fd886c9;hb=3e460831579f03b5f96703073b02052478b854df;hp=e2c3ac0cc4493dfec9710fe68c8a8cc6eeacf6fb;hpb=57fdfd3f8ec62b105c53bcdf6f127c35c7fe7391;p=gnulib.git diff --git a/lib/close-stream.c b/lib/close-stream.c index e2c3ac0cc..8819b5809 100644 --- a/lib/close-stream.c +++ b/lib/close-stream.c @@ -1,7 +1,6 @@ /* Close a stream, with nicer error checking than fclose's. - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2006, 2007 Free - Software Foundation, Inc. + Copyright (C) 1998-2002, 2004, 2006-2011 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -33,6 +32,10 @@ otherwise. A failure might set errno to 0 if the error number cannot be determined. + A failure with errno set to EPIPE may or may not indicate an error + situation worth signaling to the user. See the documentation of the + close_stdout_set_ignore_EPIPE function for details. + If a program writes *anything* to STREAM, that program should close STREAM and make sure that it succeeds before exiting. Otherwise, suppose that you go to the extreme of checking the return status @@ -52,9 +55,9 @@ int close_stream (FILE *stream) { - bool some_pending = (__fpending (stream) != 0); - bool prev_fail = (ferror (stream) != 0); - bool fclose_fail = (fclose (stream) != 0); + const bool some_pending = (__fpending (stream) != 0); + const bool prev_fail = (ferror (stream) != 0); + const bool fclose_fail = (fclose (stream) != 0); /* Return an error indication if there was a previous failure or if fclose failed, with one exception: ignore an fclose failure if @@ -67,7 +70,7 @@ close_stream (FILE *stream) if (prev_fail || (fclose_fail && (some_pending || errno != EBADF))) { if (! fclose_fail) - errno = 0; + errno = 0; return EOF; }