1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" This manpage is Copyright (C) 1992 Drew Eckhardt;
4 .\" 1993 Michael Haardt, Ian Jackson.
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date. The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein. The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
26 .\" Modified Sat Jul 24 13:35:59 1993 by Rik Faith <faith@cs.unc.edu>
27 .\" Modified Sun Nov 28 17:19:01 1993 by Rik Faith <faith@cs.unc.edu>
28 .\" Modified Sat Jan 13 12:58:08 1996 by Michael Haardt
29 .\" <michael@cantor.informatik.rwth-aachen.de>
30 .\" Modified Sun Jul 21 18:59:33 1996 by Andries Brouwer <aeb@cwi.nl>
31 .\" 2001-12-13 added remark by Zack Weinberg
33 .TH WRITE 2 2001-12-13 "Linux 2.0.32" "Linux Programmer's Manual"
35 write \- write to a file descriptor
37 .B #include <unistd.h>
39 .BI "ssize_t write(int " fd ", const void *" buf ", size_t " count );
44 bytes to the file referenced by the file descriptor
46 from the buffer starting at
48 POSIX requires that a \fBread()\fP which can be proved to occur after a
49 \fBwrite()\fP has returned returns the new data. Note that not all file
50 systems are POSIX conforming.
52 On success, the number of bytes written are returned (zero indicates
53 nothing was written). On error, \-1 is returned, and \fIerrno\fP is set
54 appropriately. If \fIcount\fP is zero and the file descriptor refers to
55 a regular file, 0 will be returned without causing any other effect.
56 For a special file, the results are not portable.
60 Non-blocking I/O has been selected using
62 and the write would block.
66 is not a valid file descriptor or is not open for writing.
70 is outside your accessible address space.
73 An attempt was made to write a file that exceeds the implementation-defined
74 maximum file size or the process' file size limit, or to write at a position
75 past than the maximum allowed offset.
78 The call was interrupted by a signal before any data was written.
82 is attached to an object which is unsuitable for writing;
83 or the file was opened with the
85 flag, and either the address specified in
87 the value specified in
89 or the current file offset is not suitably aligned.
92 A low-level I/O error occurred while modifying the inode.
95 The device containing the file referred to by
97 has no room for the data.
101 is connected to a pipe or socket whose reading end is closed. When this
102 happens the writing process will also receive a
105 (Thus, the write return value is seen only if the program
106 catches, blocks or ignores this signal.)
108 Other errors may occur, depending on the object connected to
111 SVr4, SVID, POSIX, X/OPEN, 4.3BSD. SVr4 documents additional error
112 conditions EDEADLK, ENOLCK, ENOLNK, ENOSR, ENXIO, or ERANGE.
113 Under SVr4 a write may be interrupted and return EINTR at any point,
114 not just before any data is written.
116 A successful return from
118 does not make any guarantee that data has been committed to disk.
119 In fact, on some buggy implementations, it does not even guarantee
120 that space has successfully been reserved for the data.
121 The only way to be sure is to call
123 after you are done writing all your data.