write.2 (2010 09)
w
write(2) write(2)
performed by the owner or a user who has appropriate privileges, the behavior is file-system dependent.
In some file systems, the write clears the set-user-ID, set-group-ID, and sticky bits on a nondirectory file.
In other file systems, the write does not clear these bits on a nondirectory file.
For directories,
write() does not clear the set-user-ID, set-group-ID, and sticky bits.
The
writev() function is equivalent to write()
, but gathers the output data from the iovcnt buffers
specified by the members of the iov array: iov [0], iov[1], ..., iov [iovcnt −1]. iovcnt is valid if greater than
0 and less than or equal to
{IOV_MAX}
, as defined in <limits.h>.
Each iovec entry specifies the base address and length of an area in memory from which data should be
written. The
writev() function will always write a complete area before proceeding to the next. The
iovec structure is defined in /usr/include/sys/uio.h
.
If fildes refers to a regular file and all of the iov_len members in the array pointed to by iov are 0,
wri-
tev() will return 0 and have no other effect. For other file types, the behavior is unspecified.
If the sum of the iov_len values is greater than
SSIZE_MAX, the operation fails and no data is
transferred.
The
pwrite() function performs the same action as
write(), except that it writes into a given posi-
tion without changing the file pointer. The first three arguments to
pwrite() are the same as
write() with the addition of a fourth argument offset for the desired position inside the file.
When a
write() system call executes on a local file system and needs a new buffer to be allocated to
hold the data, the buffer maps onto the disk at that time. If the disk is full,
write() returns an error
and
errno is set to [ENOSPC].
When a
write() system call executes on an NFS file system, the write() allocates the new buffer
without communicating with the NFS server to see if there is space for the buffer (to improve NFS perfor-
mance). The disk-full condition is checked, only when the buffer is written to the server (at file close or
the buffer is full). If the disk is full, close() returns an error. See close (2).
RETURN VALUE
Upon successful completion,
write() and pwrite() will return the number of bytes actually written
to the file associated with fildes. This number will never be greater than nbyte . Otherwise,
−1 is
returned and
errno is set to indicate the error.
Upon successful completion,
writev() returns the number of bytes actually written. Otherwise, it
returns a value of −1, the file pointer remains unchanged, and errno is set to indicate an error.
A write to a
STREAMS file may fail if an error message has been received at the
STREAM head. In this
case,
errno is set to the value included in the error message.
ERRORS
Under the following conditions,
write(), pwrite() and writev() fail and set errno to:
[EAGAIN] The
O_NONBLOCK flag was set for the file descriptor and the process was delayed in
the write() operation.
[EAGAIN] Enforcement-mode file and record locking was set,
O_NDELAY was set, and there
was a blocking record lock.
[EBADF] The fildes argument was not a valid file descriptor open for writing.
[EDEADLK] A resource deadlock would occur as a result of this operation (see lockf (2) and
fcntl (2)).
[EDQUOT] User’s disk quota block limit has been reached for this file system.
[EFBIG] An attempt was made to write a file that exceeds the implementation-dependent
maximum file size or the process’ file size limit.
[EFBIG] The file is a regular file and nbyte is greater than zero and the starting position is
greater than or equal to the offset maximum established in the open file description
associated with fildes.
[EINTR] The write operation was terminated due to the receipt of a signal, and no data was
transferred.
[EINVAL] The
STREAM or multiplexer referenced by fildes is linked (directly or indirectly)
downstream from a multiplexer.
HP-UX 11i Version 3: September 2010 − 3 − Hewlett-Packard Company 3