1WRITE(2)                   Linux Programmer's Manual                  WRITE(2)
2
3
4

NAME

6       write - write to a file descriptor
7

SYNOPSIS

9       #include <unistd.h>
10
11       ssize_t write(int fd, const void *buf, size_t count);
12

DESCRIPTION

14       write() writes up to count bytes from the buffer starting at buf to the
15       file referred to by the file descriptor fd.
16
17       The number of bytes written may be less than  count  if,  for  example,
18       there  is  insufficient space on the underlying physical medium, or the
19       RLIMIT_FSIZE resource limit is encountered (see setrlimit(2)),  or  the
20       call was interrupted by a signal handler after having written less than
21       count bytes.  (See also pipe(7).)
22
23       For a seekable file (i.e., one to which lseek(2) may  be  applied,  for
24       example,  a  regular  file) writing takes place at the file offset, and
25       the file offset is incremented by the number of bytes actually written.
26       If  the  file was open(2)ed with O_APPEND, the file offset is first set
27       to the end of the file before writing.  The adjustment of the file off‐
28       set and the write operation are performed as an atomic step.
29
30       POSIX  requires  that  a  read(2)  that  can be proved to occur after a
31       write() has returned will return the  new  data.   Note  that  not  all
32       filesystems are POSIX conforming.
33
34       According to POSIX.1, if count is greater than SSIZE_MAX, the result is
35       implementation-defined; see NOTES for the upper limit on Linux.
36

RETURN VALUE

38       On success, the number of bytes written is returned.  On error,  -1  is
39       returned, and errno is set to indicate the error.
40
41       Note  that  a  successful  write() may transfer fewer than count bytes.
42       Such partial writes can occur for various reasons; for example, because
43       there was insufficient space on the disk device to write all of the re‐
44       quested bytes, or because a blocked write() to a socket, pipe, or simi‐
45       lar  was interrupted by a signal handler after it had transferred some,
46       but before it had transferred all of the requested bytes.  In the event
47       of  a partial write, the caller can make another write() call to trans‐
48       fer the remaining bytes.  The subsequent call will either transfer fur‐
49       ther bytes or may result in an error (e.g., if the disk is now full).
50
51       If  count is zero and fd refers to a regular file, then write() may re‐
52       turn a failure status if one of the errors below is  detected.   If  no
53       errors are detected, or error detection is not performed, 0 is returned
54       without causing any other effect.  If count is zero and fd refers to  a
55       file other than a regular file, the results are not specified.
56

ERRORS

58       EAGAIN The  file descriptor fd refers to a file other than a socket and
59              has been marked nonblocking (O_NONBLOCK), and  the  write  would
60              block.  See open(2) for further details on the O_NONBLOCK fl