HP-UX Reference (11i v2 03/08) - 2 System Calls (vol 5)
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.
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.
[EIO] A physical I/O error has occurred.
[EIO] The process is a member of a background process group attempting to write to its
controlling terminal.
TOSTOP is set, the process is neither ignoring nor blocking
SIGTTOU, and the process group of the process is orphaned. This error may also be
returned under implementation-dependent conditions.
[ENOLCK] The system record lock table is full, preventing the write from sleeping until the
blocking record lock is removed.
Section 2−−490 Hewlett-Packard Company − 3 − HP-UX 11i Version 2: August 2003