Re: Strange pager (less, more) behavior
- From: Måns Rullgård <mru@xxxxxxxxxxxxx>
- Date: Wed, 29 Mar 2006 23:19:38 +0100
Kasper Dupont
<31026663590054698937@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> writes:
Måns Rullgård wrote:
Closing stdout is fine, and the correct thing to do in this case. If
you do not close it, you have no chance of detecting errors in the
final buffer flush.
I'd rather use fflush to check for write errors on stdout.
Network filesystems with aggressive caching may not report an error
(such as insufficient disk space) until the file is closed.
There is no reason for not closing stdin/out/err. They are all
closed automatically on program exit anyway, so there is no
externally visible difference.
I would worry about what is going to happen when stdio is going
to access stdout on exit. Usually I consider whoever opens a file
responsible to close it again. But if any part of a program copy
a pointer to stdout and eventually close it, you may easilly have
many attempts to close it, and somebody may try to access it after
it has been closed.
If you use strace on the program, there is a visible difference
between calling fclose(stdout) and letting stdio deal with it on
exit. In the first case there is a close(1) system call, there is
none in the second case.
I can't find anything in the C99 standard explicitly allowing or
disallowing fclose() on the stdio streams. The closest I get is this
sentence: The value of a pointer to a FILE object is indeterminate
after the associated file is closed (including the standard text
streams). I suppose this could be taken as an implicit permission to
close these streams. I've never seen or heard of any ill effects from
doing so either.
--
Måns Rullgård
mru@xxxxxxxxxxxxx
.
- References:
- Strange pager (less, more) behavior
- From: Dave Ulrick
- Re: Strange pager (less, more) behavior
- From: Måns Rullgård
- Strange pager (less, more) behavior
- Prev by Date: Re: Playback utility
- Next by Date: Re: Strange pager (less, more) behavior
- Previous by thread: Re: Strange pager (less, more) behavior
- Next by thread: Re: Strange pager (less, more) behavior
- Index(es):
Relevant Pages
|