What's the practical use of the error close() returns?
Baruch Even
baruch at ev-en.org
Fri Jul 27 19:23:05 IDT 2012
On Fri, Jul 27, 2012 at 7:06 PM, Oleg Goldshmidt <pub at goldshmidt.org> wrote:
>
> On Fri, Jul 27, 2012 at 2:52 PM, Elazar Leibovich <elazarl at gmail.com> wrote:
>
> > You nailed it! closing a file twice is an error that makes sense to be
> > issued at close. So simple, how could I miss it?
>
> Not only for catching your bugs. If fclose(3) returns an error any
> further access to the descriptor, including another call to
> fclose(3), results in undefined behaviour, and I'd regard that as the
> scariest thing that can happen to a program.
>
> There is another reason to check the status: a call to close() might
> have been interrupted by a signal. In some cases the call may be
> resumed after the signal is handled, in some cases the call returns an
> error status (errno=EINTR usually?). I suppose you want to know
> whether the descriptor was or was not closed.
This might not really be helpful to know, the file descriptor is left in an
unspecified state according to POSIX, see:
http://utcc.utoronto.ca/~cks/space/blog/unix/CloseEINTR
Baruch
More information about the Linux-il
mailing list