[cs631apue] doubt on read()

Jan Schaumann jschauma at stevens.edu
Fri Dec 1 13:23:50 EST 2017


Jeevanandha Ramanathan <jramana1 at stevens.edu> wrote:
 
> When I read from the file descriptor, it's efficient to read in
> iteration of the BLOCKSIZE, but what happens if I read the entire file
> into the buffer in just one read() call?

You are assuming that you _can_ read the entire file into memory in one
read(2) call.  You may be able to, but you also may not.

If you ask read(2) to read more bytes than are available, read(2) will
try to read all the bytes available and then return the number of bytes
read; that number will then be less than the requested number.

Revisit lecture 02 and Stevens chapter 3.

-Jan


More information about the cs631apue mailing list