Loading AI tools
From Wikipedia, the free encyclopedia
In modern POSIX compliant 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.
This article includes a list of references, related reading, or external links, but its sources remain unclear because it lacks inline citations. (February 2019) |
The read system call takes three arguments:
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 end of file) and the file position is advanced by this number. It is not an error if this number is smaller than the number of bytes requested; this may happen for example because fewer bytes are actually available right now (maybe because we were close to end-of-file, or because we are reading from a pipe, or from a terminal), or because the system call was interrupted by a 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.
Seamless Wikipedia browsing. On steroids.
Every time you click a link to Wikipedia, Wiktionary or Wikiquote in your browser's search results, it will show the modern Wikiwand interface.
Wikiwand extension is a five stars, simple, with minimum permission required to keep your browsing private, safe and transparent.