What's the practical use of the error close() returns?
Oleg Goldshmidt
pub at goldshmidt.org
Fri Jul 27 19:59:44 IDT 2012
> 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
The fact that POSIX does not specify the fd's state is, indeed, not
helpful. The *reason* why it does not specify it is very helpful and
relevant, and it is spelled out even in the above link: by the time
POSIX was developed there already were well-established UNIX systems
some of which always closed the fd when returning EINTR and others
always left it open. So POSIX decided not to decide.
The fact that POSIX does not specify the outcome does not mean you do
not know the outcome in every case (or, at least, in most cases).
Linux always closes so there is nothing to be done if you notice
EINTR. However, if you write portable code and you HP-UX or other
platforms that leave the fd open (and there are arguments - with which
one may or may not agree, just be aware of their existence - for that
behaviour) are among your targets then you mght want to preprocess the
error handling code accordingly.
A quick google seems to show that the issue is under review at this
very moment: http://austingroupbugs.net/view.php?id=529 (if you have
not heard of Austin group, see http://www.opengroup.org/austin/).
--
Oleg Goldshmidt | pub at goldshmidt.org
More information about the Linux-il
mailing list