File System

File System read

read

// PROTOTYPE
int read(int fd, void* buf, size_t count)

Reads from a file. Reads occur at the current file position, see lseek, and end at the current end-of-file.

  • fd: The file descriptor for the file, return from the open call.
  • buf: Pointer to the buffer to read data from the file into.
  • count: Number of bytes to read to the file.

Returns the number of bytes read, which is typically count unless the end-of-file is reached, in which case the number of bytes actually read is returned. The number of bytes may be 0 if already at the end-of-file.

On error, returns -1 and sets errno. Some possible errno values include:

  • EBADF Bad fd