What's the practical use of the error close() returns?

What's the practical use of the error close() returns?

Oleg Goldshmidt pub at goldshmidt.org
Fri Jul 27 19:06:55 IDT 2012


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.

-- 
Oleg Goldshmidt | pub at goldshmidt.org



More information about the Linux-il mailing list