read

Reads bytes from a socket or file and places them in a buffer.

Format

#include  <unixio.h>

int read  (int d, void *buffer, int
          nbytes);

Arguments

d
A descriptor that must refer to a socket or file currently opened for reading.
buffer
The address of contiguous storage in which the input data is placed.
nbytes
The maximum number of bytes involved in the read operation.

Description

If the end-of-file is not reached, the read routine returns nbytes. If the end-of-file occurs during the read routine, it returns the number of bytes read.

Upon successful completion, read returns the number of bytes actually read and placed in the buffer.

See also socket in this section.

Return Values
The number of bytes read and placed in the file. 
-1  Indicates an error; errno is set to one of the following:

  • EBADF - The socket descriptor is invalid.

  • EFAULT - The buffer points outside the allocated address space.

  • EINVAL - The nbytes argument is negative.

  • EWOULDBLOCK - The NBIO socket option (nonblocking) flag is set for the socket or file descriptor and the process would be delayed in the read operation.
 


Previous Page | Next Page | Table of Contents | Index