WRITE(S) XENIX System V WRITE(S)
Name
write - Writes to a file.
Syntax
int write (fildes, buf, nbyte)
int fildes;
char *buf;
unsigned nbyte;
Description
fildes is a file descriptor obtained from a creat, open,
dup, fcntl, or pipe system call.
write attempts to write nbyte bytes from the buffer pointed
to by buf to the file associated with the fildes.
On devices capable of seeking, the actual writing of data
proceeds from the position in the file indicated by the file
pointer. Upon return from write, the file pointer is
incremented by the number of bytes actually written.
On devices incapable of seeking, writing always takes place
starting at the current position. The value of a file
pointer associated with such a device is undefined.
If the O_APPEND flag of the file status flags is set, the
file pointer is set to the end of the file prior to each
write.
write will fail and the file pointer will remain unchanged
if one or more of the following are true:
fildes is not a valid file descriptor open for writing.
[EBADF]
An attempt is made to write to a pipe that is not open
for reading by any process. [EPIPE and SIGPIPE signal]
An attempt was made to write a file that exceeds the
process' file size limit or the maximum file size. See
ulimit(S). [EFBIG]
buf points outside the process' allocated address
space. [EFAULT]
A signal was caught during the write system call.
[EINTR]
There is no free space remaining on the device
containing the file.
If a write requests that more bytes be written than there is
Page 1 (printed 8/7/87)
WRITE(S) XENIX System V WRITE(S)
room for (e.g., the ulimit (see ulimit(S)) or the physical
end of a medium), only as many bytes as there is room for
will be written. For example, suppose there is space for 20
bytes more in a file before reaching a limit. A write of
512 bytes will return 20. The next write of a nonzero
number of bytes gives a failure return (except as noted
below).
If the file being written is a pipe (or FIFO), no partial
writes are permitted. Thus, the write will fail if a write
of nbyte bytes exceeds a limit.
If the file being written is a pipe (or FIFO) and the
O_NDELAY flag of the file flag word is set, then a write to
a full pipe (or FIFO) returns a count of 0. Otherwise
(O_NDELAY clear), writes to a full pipe (or FIFO) block
until space becomes available.
Return Value
Upon successful completion, the number of bytes actually
written is returned. Otherwise, -1 is returned and errno is
set to indicate the error.
See Also
creat(S), dup(S), lseek(S), open(S), pipe(S), ulimit(S)
Notes
Writing a region of a file locked with locking causes write
to hang indefinitely until the locked region is unlocked.
Page 2 (printed 8/7/87)