[9] | 1 | .\" Copyright (c) 1980 Regents of the University of California.
|
---|
| 2 | .\" All rights reserved. The Berkeley software License Agreement
|
---|
| 3 | .\" specifies the terms and conditions for redistribution.
|
---|
| 4 | .\"
|
---|
| 5 | .\" @(#)write.2 6.5 (Berkeley) 5/14/86
|
---|
| 6 | .\"
|
---|
| 7 | .TH WRITE 2 "May 14, 1986"
|
---|
| 8 | .UC 4
|
---|
| 9 | .SH NAME
|
---|
| 10 | write \- write output
|
---|
| 11 | .SH SYNOPSIS
|
---|
| 12 | .nf
|
---|
| 13 | .ft B
|
---|
| 14 | #include <sys/types.h>
|
---|
| 15 | #include <unistd.h>
|
---|
| 16 |
|
---|
| 17 | ssize_t write(int \fId\fP, const void *\fIbuf\fP, size_t \fInbytes\fP)
|
---|
| 18 | .fi
|
---|
| 19 | .SH DESCRIPTION
|
---|
| 20 | .B Write
|
---|
| 21 | attempts to write
|
---|
| 22 | .I nbytes
|
---|
| 23 | of data to the object referenced by the descriptor
|
---|
| 24 | .I d
|
---|
| 25 | from the buffer pointed to by
|
---|
| 26 | .IR buf .
|
---|
| 27 | .PP
|
---|
| 28 | On objects capable of seeking, the \fBwrite\fP starts at a position
|
---|
| 29 | given by the pointer associated with
|
---|
| 30 | .IR d ,
|
---|
| 31 | see
|
---|
| 32 | .BR lseek (2).
|
---|
| 33 | Upon return from
|
---|
| 34 | .BR write ,
|
---|
| 35 | the pointer is incremented by the number of bytes actually written.
|
---|
| 36 | .PP
|
---|
| 37 | Objects that are not capable of seeking always write from the current
|
---|
| 38 | position. The value of the pointer associated with such an object
|
---|
| 39 | is undefined.
|
---|
| 40 | .PP
|
---|
| 41 | When using non-blocking I/O on objects such as TCP/IP channels that are
|
---|
| 42 | subject to flow control,
|
---|
| 43 | .B write
|
---|
| 44 | may write fewer bytes than requested;
|
---|
| 45 | the return value must be noted,
|
---|
| 46 | and the remainder of the operation should be retried when possible.
|
---|
| 47 | .SH "RETURN VALUE
|
---|
| 48 | Upon successful completion the number of bytes actually written
|
---|
| 49 | is returned. Otherwise a \-1 is returned and the global variable
|
---|
| 50 | .B errno
|
---|
| 51 | is set to indicate the error.
|
---|
| 52 | .SH ERRORS
|
---|
| 53 | .B Write
|
---|
| 54 | will fail and the file pointer will remain unchanged if one or more
|
---|
| 55 | of the following are true:
|
---|
| 56 | .TP 15
|
---|
| 57 | [EBADF]
|
---|
| 58 | \fID\fP is not a valid descriptor open for writing.
|
---|
| 59 | .TP 15
|
---|
| 60 | [EPIPE]
|
---|
| 61 | An attempt is made to write to a pipe that is not open
|
---|
| 62 | for reading by any process.
|
---|
| 63 | .TP 15
|
---|
| 64 | [EPIPE]
|
---|
| 65 | An attempt is made to write to a TCP channel
|
---|
| 66 | that is not connected to a peer socket.
|
---|
| 67 | .TP 15
|
---|
| 68 | [EFBIG]
|
---|
| 69 | An attempt was made to write a file that exceeds the process's
|
---|
| 70 | file size limit or the maximum file size.
|
---|
| 71 | .TP 15
|
---|
| 72 | [EFAULT]
|
---|
| 73 | Part of the data to be written to the file
|
---|
| 74 | points outside the process's allocated address space.
|
---|
| 75 | .TP 15
|
---|
| 76 | [ENOSPC]
|
---|
| 77 | There is no free space remaining on the file system
|
---|
| 78 | containing the file.
|
---|
| 79 | .ig
|
---|
| 80 | .TP 15
|
---|
| 81 | [EDQUOT]
|
---|
| 82 | The user's quota of disk blocks on the file system
|
---|
| 83 | containing the file has been exhausted.
|
---|
| 84 | ..
|
---|
| 85 | .TP 15
|
---|
| 86 | [EIO]
|
---|
| 87 | An I/O error occurred while reading from or writing to the file system.
|
---|
| 88 | .TP 15
|
---|
| 89 | [EAGAIN]
|
---|
| 90 | The file was marked for non-blocking I/O,
|
---|
| 91 | and no data could be written immediately.
|
---|
| 92 | .SH "SEE ALSO"
|
---|
| 93 | .BR fcntl (2),
|
---|
| 94 | .BR lseek (2),
|
---|
| 95 | .BR open (2),
|
---|
| 96 | .BR pipe (2),
|
---|
| 97 | .BR read (2).
|
---|