File System

File System write

write

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

Writes to a file. If the file was opened with flag O_APPEND then the file is appended to. Otherwise, writes occur at the current file position, see lseek.

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

Returns the number of bytes written, which is typically count

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

  • EBADF Bad fd.
  • ENOSPC There is no space on the file system.