read (system call)

Source: Wikipedia, the free encyclopedia.

In modern

operating systems, a program that needs to access data from a file stored in a file system uses the read system call. The file is identified by a file descriptor that is normally obtained from a previous call to open. This system call reads in data in bytes
, the number of which is specified by the caller, from the file and stores then into a buffer supplied by the calling process.

The read system call takes three arguments:

  1. The file descriptor of the file.
  2. the buffer where the read data is to be stored and
  3. the number of bytes to be read from the file.

POSIX usage

The read system call interface is standardized by the POSIX specification. Data from a file is read by calling the read function:

ssize_t read(int fd, void *buf, size_t count);

The value returned is the number of bytes read (zero indicates

signal
.

Alternatively, -1 is returned when an error occurs, in such a case

errno
is set appropriately and further it is left unspecified whether the file position (if any) changes.

See also

References

External links