Re: cvs commit: src/sys/kern sys_generic.c
On Tue, Jan 25, 2005 at 10:53:33AM +0100, Poul-Henning Kamp wrote:
> That would be just as bogus as the fact that open(2) doesn't affect atime.
Well, SUSv3 says that "upon successful completion, where nbyte is
greater than 0, read() shall mark for update the st_atime", so I tend to
agree about atime here.
But... There other issues about zero-bytes reads. SUSv3 says:
"Before any action described below is taken, and if nbyte is zero, the
read() function may detect and return errors as described below. In the
absence of errors, or if error detection is not performed, the read()
function shall return zero and have no other results."
Then, it correct this position a bit:
"This volume of IEEE Std 1003.1-2001 requires that no action be taken for
read() or write() when nbyte is zero. This is not intended to take
precedence over detection of errors (such as invalid buffer pointers or
file descriptors). This is consistent with the rest of this volume of IEEE
Std 1003.1-2001, but the phrasing here could be misread to require
detection of the zero case before any other errors. A value of zero is to
be considered a correct value, for which the semantics are a no-op."
Then, there are more practical examples:
"When attempting to read from an empty pipe or FIFO:
If some process has the pipe open for writing and O_NONBLOCK is set,
read() shall return -1 and set errno to [EAGAIN].
If some process has the pipe open for writing and O_NONBLOCK is clear,
read() shall block the calling thread until some data is written or the
pipe is closed by all processes that had the pipe open for writing."
That means, zero bytes read too.
Now more about zero-bytes and streams:
"How read() handles zero-byte STREAMS messages is determined by the
current read mode setting. In byte-stream mode, read() shall accept data
until it has read nbyte bytes, or until there is no more data to read, or
until a zero-byte message block is encountered. The read() function shall
then return the number of bytes read, and place the zero-byte message back
on the STREAM to be retrieved by the next read(), getmsg(), or getpmsg().
In message-nondiscard mode or message-discard mode, a zero-byte message
shall return 0 and the message shall be removed from the STREAM. When a
zero-byte message is read as the first message on a STREAM, the message
shall be removed from the STREAM and 0 shall be returned, regardless of
the read mode."
And so on...
Received on Tue Jan 25 2005 - 10:15:00 UTC