1 .\" $NetBSD: write.2,v 1.29 2006/10/13 20:58:50 wiz Exp $
3 .\" Copyright (c) 1980, 1991, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" @(#)write.2 8.5 (Berkeley) 4/2/94
46 .Fn write "int d" "const void *buf" "size_t nbytes"
48 .Fn pwrite "int d" "const void *buf" "size_t nbytes" "off_t offset"
51 .Fn writev "int d" "const struct iovec *iov" "int iovcnt"
53 .Fn pwritev "int d" "const struct iovec *iov" "int iovcnt" "off_t offset"
58 of data to the object referenced by the descriptor
60 from the buffer pointed to by
63 performs the same action, but gathers the output data
66 buffers specified by the members of the
68 array: iov[0], iov[1], ..., iov[iovcnt\|-\|1].
72 perform the same functions, but write to the specified position in
73 the file without modifying the file pointer.
81 structure is defined as:
83 .Bd -literal -offset indent -compact
92 entry specifies the base address and length of an area
93 in memory from which data should be written.
97 will always write a complete area before proceeding
100 On objects capable of seeking, the
103 given by the pointer associated with
109 the pointer is incremented by the number of bytes which were written.
111 Objects that are not capable of seeking always write from the current
113 The value of the pointer associated with such an object
116 If the real user is not the super-user, then
118 clears the set-user-id bit on a file.
119 This prevents penetration of system security
122 a writable set-user-id file
123 owned by the super-user.
127 succeeds it will update the st_ctime and st_mtime fields of the file's
131 When using non-blocking I/O on objects such as sockets that are subject
136 may write fewer bytes than requested;
137 the return value must be noted,
138 and the remainder of the operation should be retried when possible.
140 Upon successful completion the number of bytes which were written
142 Otherwise a \-1 is returned and the global variable
144 is set to indicate the error.
151 will fail and the file pointer will remain unchanged if:
155 is not a valid descriptor open for writing.
157 An attempt is made to write to a pipe that is not open
158 for reading by any process.
160 An attempt is made to write to a socket of type
162 that is not connected to a peer socket.
164 An attempt was made to write a file that exceeds the process's
165 file size limit or the maximum file size.
169 or data to be written to the file
170 points outside the process's allocated address space.
172 The pointer associated with
176 The total length of the I/O is more than can be expressed by the ssize_t
179 There is no free space remaining on the file system
182 The user's quota of disk blocks on the file system
183 containing the file has been exhausted.
185 An I/O error occurred while reading from or writing to the file system.
187 A signal was received before any data could be written to a slow
191 for more information on the interaction between signals and system
194 The file was marked for non-blocking I/O,
195 and no data could be written immediately.
202 may return one of the following errors:
206 was less than or equal to 0, or greater than
219 array overflowed a 32-bit integer.
226 calls may also return the following errors:
229 The specified file offset is invalid.
231 The file descriptor is associated with a pipe, socket, or FIFO.
244 function is expected to conform to
270 function call appeared in
273 Error checks should explicitly test for \-1.
276 while ((nr = write(fd, buf, sizeof(buf))) \*[Gt] 0)
279 is not maximally portable, as some platforms allow for
285 \- 2, in which case the return value of an error-free
287 may appear as a negative number distinct from \-1.
288 Proper loops should use
290 while ((nr = write(fd, buf, sizeof(buf))) != -1 \*[Am]\*[Am] nr != 0)