richard
8/8/2008 11:48:00 PM
In article <ln4p5v169w.fsf@nuthaus.mib.org>,
Keith Thompson <kst-u@mib.org> wrote:
>If you've been writing to a stream (fp, stdout, whatever), it can have
>buffered data that hasn't yet been written to the physical file (your
>screen, foo.dat, whatever). Either flushing or closing the stream
>will cause the system to *attempt* to write out any buffered data, or
>at least to pass it on to another part of the system that will
>eventually write it to the physical media. In either case, that can
>fail for any number of reasons: the disk might be full, you might have
>unplugged something, etc.
fflush() may well succeed even though the data has not yet reached its
destination. fclose() on the other hand should not return until
the lower levels have reported success. Write failures can be caused
by common things like full filesystems, and the failure may not be
immediate for a networked fileserver.
>When writing to stdout or stderr, it's fairly common to omit checks,
>since (a) any failure will often be fairly obvious to the user, and
>(b) there's not much you can do to recover (where do you write the
>error message?).
You may not be able to recover, but you can avoid taking some
destructive action like deleting the input file.
>For anything else, you should always check the
>result of every I/O operation, even if all you do in the event of
>failure is to abort the program with an error message.
Or check ferror() at the end of a loop, if it's tedious to check every
operation. But don't do this for infinite, or even very lengthy,
loops.
-- Richard
--
Please remember to mention me / in tapes you leave behind.