]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/write.2
Automated addition of parentheses by add_parens_for_own_funcs.sh
[thirdparty/man-pages.git] / man2 / write.2
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" This manpage is Copyright (C) 1992 Drew Eckhardt;
4 .\" 1993 Michael Haardt, Ian Jackson.
5 .\"
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.
9 .\"
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.
14 .\"
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
21 .\" professionally.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
25 .\"
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
32 .\"
33 .TH WRITE 2 2001-12-13 "Linux 2.0.32" "Linux Programmer's Manual"
34 .SH NAME
35 write \- write to a file descriptor
36 .SH SYNOPSIS
37 .B #include <unistd.h>
38 .sp
39 .BI "ssize_t write(int " fd ", const void *" buf ", size_t " count );
40 .SH DESCRIPTION
41 .BR write ()
42 writes up to
43 .I count
44 bytes to the file referenced by the file descriptor
45 .I fd
46 from the buffer starting at
47 .IR buf .
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.
51 .SH "RETURN VALUE"
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.
57 .SH ERRORS
58 .TP
59 .B EAGAIN
60 Non-blocking I/O has been selected using
61 .B O_NONBLOCK
62 and the write would block.
63 .TP
64 .B EBADF
65 .I fd
66 is not a valid file descriptor or is not open for writing.
67 .TP
68 .B EFAULT
69 .I buf
70 is outside your accessible address space.
71 .TP
72 .B EFBIG
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.
76 .TP
77 .B EINTR
78 The call was interrupted by a signal before any data was written.
79 .TP
80 .B EINVAL
81 .I fd
82 is attached to an object which is unsuitable for writing;
83 or the file was opened with the
84 .B O_DIRECT
85 flag, and either the address specified in
86 .IR buf ,
87 the value specified in
88 .IR count ,
89 or the current file offset is not suitably aligned.
90 .TP
91 .B EIO
92 A low-level I/O error occurred while modifying the inode.
93 .TP
94 .B ENOSPC
95 The device containing the file referred to by
96 .I fd
97 has no room for the data.
98 .TP
99 .B EPIPE
100 .I fd
101 is connected to a pipe or socket whose reading end is closed. When this
102 happens the writing process will also receive a
103 .B SIGPIPE
104 signal.
105 (Thus, the write return value is seen only if the program
106 catches, blocks or ignores this signal.)
107 .PP
108 Other errors may occur, depending on the object connected to
109 .IR fd .
110 .SH "CONFORMING 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.
115 .SH NOTES
116 A successful return from
117 .BR write ()
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
122 .BR fsync (2)
123 after you are done writing all your data.
124 .SH "SEE ALSO"
125 .BR close (2),
126 .BR fcntl (2),
127 .BR fsync (2),
128 .BR ioctl (2),
129 .BR lseek (2),
130 .BR open (2),
131 .BR read (2),
132 .BR select (2),
133 .BR fwrite (3),
134 .BR writev (3)