>I must admit that I *really* like to know which idiot decided
>to implement O_NDELAY is this way that *totally* breaks the
>semantics of read(2).
>And who had it first? BSD 4.? Sys III ? Sys Vr?
Unfortunately I don't have a 4.3BSD system running anymore, but I seem to
recall (and some lingering evidence indicates) that the way to set
non-blocking mode was with the FIONBIO *ioctl*, and that the fcntl
implementation was rather half-hearted and mostly for SysV compatibility -
it may well have included a similarly broken O_NDELAY - again, for SysV
compatibility; I'm confident BSD didn't invent such a stupid thing!:-)
Quote:>It seems that the best choice therefor is to test for O_NONBLOCK
>and use that if it exists. It has well-defined behaviour.
Well, the problem with SunOS 4 is as I mentioned that O_NONBLOCK exists
(and appears to work with fcntl), and is documented for *some* cases
(e.g. open(2)), but not for use with fcntl - specifically, fcntl(2) says:
F_SETFL Set descriptor status flags (see fcntl(5) for
definitions). The following flags are the
only ones whose values may change: O_APPEND,
O_SYNC, and O_NDELAY, and the FASYNC, FNDE-
LAY, and FNBIO flags defined in <fcntl.h>.
- of course none of those flags are defined in <fcntl.h> but in
<sys/fcntlcom.h>, #included by fcntl.h, and none of them are the same as
O_NONBLOCK, and fcntlcom.h also claims that FAPPEND and FSYNC (which are
the same as O_APPEND and O_SYNC), and FNONBIO (!) (which is the same as
O_NONBLOCK!) work for the F_SETFL fcntl. Hmm, I guess if I didn't lose
myself somewhere in that maze, and include files can be regarded as
documentation, that the answer is that fcntl(fd, F_SETFL, O_NONBLOCK)
*is* (sort of:-) documented to work...