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 to the file referenced by the file
15       descriptor fd from the buffer starting at buf.  POSIX requires  that  a
16       read()  which  can  be  proved  to  occur  after a write() has returned
17       returns the new data.  Note that not all file systems  are  POSIX  con‐
18       forming.
19

RETURN VALUE

21       On  success,  the  number of bytes written are returned (zero indicates
22       nothing was written).  On error, -1  is  returned,  and  errno  is  set
23       appropriately.
24
25       If  count  is  zero  and fd refers to a regular file, then write () may
26       return a failure status if one of the errors below is detected.  If  no
27       errors  are  detected,  0  will  be  returned without causing any other
28       effect.  If count is zero and fd refers to a file other than a  regular
29       file, the results are not specified.
30

ERRORS

32       EAGAIN Non-blocking  I/O  has  been  selected  using O_NONBLOCK and the
33              write would block.
34
35       EBADF  fd is not a valid file descriptor or is not open for writing.
36
37       EFAULT buf is outside your accessible address space.
38
39       EFBIG  An attempt was made to write a file that exceeds the implementa‐
40              tion-defined  maximum file size or the process' file size limit,
41              or to write at a position past the maximum allowed offset.
42
43       EINTR  The call was interrupted by a signal before any data  was  writ‐
44              ten.
45
46       EINVAL fd  is attached to an object which is unsuitable for writing; or
47              the file was opened with  the  O_DIRECT  flag,  and  either  the
48              address  specified  in buf, the value specified in count, or the
49              current file offset is not suitably aligned.
50
51       EIO    A low-level I/O error occurred while modifying the inode.
52
53       ENOSPC The device containing the file referred to by fd has no room for
54              the data.
55
56       EPIPE  fd is connected to a pipe or socket whose reading end is closed.
57              When this happens the writing process will also receive  a  SIG‐
58              PIPE  signal.  (Thus, the write return value is seen only if the
59              program catches, blocks or ignores this signal.)
60
61       Other errors may occur, depending on the object connected to fd.
62

CONFORMING TO

64       SVr4, 4.3BSD, POSIX.1-2001.
65
66       Under SVr4 a write may be interrupted and return EINTR  at  any  point,
67       not just before any data is written.
68

NOTES

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

SEE ALSO

77       close(2),  fcntl(2),  fsync(2), ioctl(2), lseek(2), open(2), pwrite(2),
78       read(2), select(2), writev(2), fwrite(3)
79
80
81
82Linux 2.0.32                      2001-12-13                          WRITE(2)
Impressum