Home > Articles > Operating Systems, Server > Linux/UNIX/Open Source

  • Print
  • + Share This
This chapter is from the book

3.8 write Function

Data is written to an open file with the write function.

    #include <unistd.h>

    ssize_t write(int filedes, 
const void *buff, size_t
nbytes); Returns: number of bytes
written if OK, -1 on error

The return value is usually equal to the nbytes argument, otherwise an error has occurred. A common cause for a write error is either filling up a disk or exceeding the file size limit for a given process (Section 7.11 and Exercise 10.11).

For a regular file, the write starts at the file's current offset. If the O_APPEND option was specified in the open, the file's offset is set to the current end of file before each write operation. After a successful write, the file's offset is incremented by the number of bytes actually written.

  • + Share This
  • 🔖 Save To Your Account