On Thu, 4 Mar 1999, Sebastien Carpe wrote:
David Starks-Browning wrote:
>
> This sounds like a well-known and often discussed topic related to
> text vs. binary file processing in cygwin. Have you searched the
> cygwin archives and checked with them on their list?
Well, may be the read behavior has been discussed many times on cygwin, may be
some are begging so that read feed the maximum bytes b4 returning, but, as far
as i can think, there is nothing in my manual page (HPUX's one) that can make
one think read always feed the maximum bytes to the buffer. It just says : read
returns the number of byte read (up to the maximum specified in the 3rd
argument), and -1 if there's a problem.
So, i still consider that exiting when read didn't feed the maximum bytes is a
bad behavior, and even a bug, since it cause all the mails left to be lost.
Honestly, I don't know the answer to this question. However, read() will
normally return the requested number of bytes, unless:
1) Interrupted by a signal
2) You've asked for non-blocking reads and there isn't enough to read
3) You've reached the end of file
I do think there should be only two exit conditions from a ReadFile() type
of function:
1) read() returns -1 : Error
2) read() returns 0 : EOF, and all done
For the others (>0), keep reading. Assuming a short read implies an EOF
would not be, in my opinion, defensive programming.
-Justin
vallon(a)mindspring.com