les@chinet.chi.il.us (Leslie Mikesell) (08/25/89)
What is supposed to happen under sysV if a pipe or FIFO contains 3 characters and a read() requests 4 characters? What about fread()? Is it documented anywhere? Les Mikesell
les@chinet.chi.il.us (Leslie Mikesell) (08/26/89)
In article <9348@chinet.chi.il.us> les@chinet.chi.il.us (Leslie Mikesell) writes: >What is supposed to happen under sysV if a pipe or FIFO contains >3 characters and a read() requests 4 characters? What about fread()? >Is it documented anywhere? I've received some mail replies that assumed that the writer was finished and had closed the writing end of the pipe, in which case both read() and fread() return the 3 available characters. I wanted to know about the case where the reader catches up, but the writer isn't finished. On SysVr3.2 (AT&T 6386), read() will return the 3 available characters, fread() will wait until 4 characters are available or EOF. This surprised me a little: ----------------- #/bin/sh READ=500 while : do echo "1" done | while : do dd bs=$READ count=1 of=/dev/null done ------------------- It gives a mixture of: 1+0 records in 1+0 records out and 0+1 records in 0+1 records out with the latter form increasing with the size of READ. Why? Les Mikesell
gwyn@smoke.BRL.MIL (Doug Gwyn) (08/28/89)
In article <9348@chinet.chi.il.us> les@chinet.chi.il.us (Leslie Mikesell) writes: >What is supposed to happen under sysV if a pipe or FIFO contains >3 characters and a read() requests 4 characters? read() returns 3 characters in such a case. >What about fread()? fread() will loop until it acquires an entire bufferful of data (typically 512 or 1024 bytes), or EOF is detected (a 0 return from read()), or an I/O error occurs (-1 return from read()). >Is it documented anywhere? Yes.