Seth Woolley's Man Viewer

Manual for write - man 2 write

([section] manual, -k keyword, -K [section] search, -f whatis)
man plain no title

WRITE(2)                   Linux Programmer's Manual                  WRITE(2)

       write(1,2) - write(1,2) to a file(1,n) descriptor

       #include <unistd.h>

       ssize_t write(1,2)(int fd, const void *buf, size_t count);

       write(1,2)  writes  up  to  count  bytes  to the file(1,n) referenced by the file(1,n)
       descriptor fd from the buffer starting at buf.  POSIX requires  that  a
       read(2,n,1 builtins)()  which  can  be  proved  to  occur  after a write(1,2)() has returned
       returns the new data.  Note that not all file(1,n) systems  are  POSIX  con-

       On  success,  the  number of bytes written are returned (zero indicates
       nothing was written).  On error(8,n), -1  is  returned,  and  errno  is  set(7,n,1 builtins)
       appropriately.   If  count  is zero and the file(1,n) descriptor refers to a
       regular file(1,n), 0 will be returned without causing any other effect.  For
       a special file(1,n), the results are not portable.

       EAGAIN Non-blocking  I/O  has  been  selected  using O_NONBLOCK and the
              write(1,2) would block.

       EBADF  fd is not a valid file(1,n) descriptor or is not open(2,3,n) for writing.

       EFAULT buf is outside your accessible address space.

       EFBIG  An attempt was made to write(1,2) a file(1,n) that exceeds the implementa-
              tion-defined  maximum file(1,n) size or the process' file(1,n) size limit,
              or to write(1,2) at a position past than the maximum allowed  offset.

       EINTR  The  call  was interrupted by a signal(2,7) before any data was writ-

       EINVAL fd is attached to an object which is unsuitable for writing.

       EIO    A low-level I/O error(8,n) occurred while modifying the inode.

       ENOSPC The device containing the file(1,n) referred to by fd has no room for
              the data.

       EPIPE  fd is connected to a pipe(2,8) or socket(2,7,n) whose reading end is closed.
              When this happens the writing process will also receive  a  SIG-
              PIPE  signal.  (Thus, the write(1,2) return value is seen only if(3,n) the
              program catches, blocks or ignores this signal.)

       Other errors may occur, depending on the object connected to fd.

       SVr4, SVID, POSIX, X/OPEN, 4.3BSD.   SVr4  documents  additional  error(8,n)
       conditions  EDEADLK,  ENOLCK,  ENOLNK,  ENOSR, ENXIO, or ERANGE.  Under
       SVr4 a write(1,2) may be interrupted and return EINTR at any point, not just
       before any data is written.

       A  successful  return  from write(1,2) does not make any guarantee that data
       has been committed to disk.  In fact, on some buggy implementations, it
       does  not  even guarantee that space has successfully been reserved for
       the data.  The only way to be sure is to call fsync(2)  after  you  are
       done writing all your data.

       close(2,7,n)(2),  fcntl(2),  fsync(2),  ioctl(2),  lseek(2), open(2,3,n)(2), read(2,n,1 builtins)(2),
       select(2,7,2 select_tut)(2), fwrite(3), writev(3)

Linux 2.0.32                      2001-12-13                          WRITE(2)

References for this manual (incoming links)