stdio/socket interaction

Rahul Dhesi dhesi%cirrusl at oliveb.ATC.olivetti.com
Thu May 31 10:53:06 AEST 1990


(4.3BSD and/or SunOS 4.0.3)

When reading from a file descriptor connected to a socket (or to a tape
device) the read() system call may return fewer bytes than requested.
Thus if a process wants to read exactly n bytes, it must loop on read()
until it has enough data (or until read() returns 0 bytes indicating
EOF).

Given this, how safe is it to use fdopen() to attach such a file
descriptor to a buffered "FILE *" file?  Is there a possible problem
with fgets(), for example, returning less than a complete line, or
fread() returning fewer items than requested, even if EOF has not been
reached?  Or does the stdio library loop on a read() and always read
the requested number of bytes?

(My SunOS 4.0.3 manual says that "fread() stops reading if an
end-of-file or error condition is encountered while reading from
'stream', or if 'nitems' items have been read," which clearly does not
allow fread() to stop reading merely because read() needs to be called
again.)

Rahul Dhesi <dhesi%cirrusl at oliveb.ATC.olivetti.com>
UUCP:  oliveb!cirrusl!dhesi



More information about the Comp.unix.wizards mailing list