HP-UX Reference (11i v1 05/09) - 2 System Calls (vol 5)
w
write(2) write(2)
HP-UX EXTENSIONS
DESCRIPTION
The iovec structure is defined in
/usr/include/sys/uio.h
.
For ordinary files, if the
O_DSYNC file status flag is set, the write does not return until both the file data
and the file attributes required to retrieve the data are physically updated. If the
O_SYNC flag is set, the
behavior is identical to that for
O_DSYNC
, with the addition that all file attributes changed by the write
operation (including access time, modification time and status change time) are also physically updated
prior to returning to the calling process.
For block special files, if the
O_DSYNC or the O_SYNC flag is set, the write does not return until the data
is physically updated. How the data reaches the physical media is implementation- and hardware-
dependent.
A write to an ordinary file is prevented if enforcement-mode file and record locking is set, and another pro-
cess owns a lock on the segment of the file being written:
If
O_NDELAY or O_NONBLOCK is set, the write returns −1 and sets errno to [EAGAIN].
If
O_NDELAY and O_NONBLOCK are clear, the write does not complete until the blocking record lock
is removed.
If the file being written is a pipe (or FIFO), the system-dependent maximum number of bytes that it can
store is given by PIPSIZ (defined in <sys/inode.h>
). The minimum value of PIPSIZ on any HP-UX
system is 8192. When writing a pipe, the following conditions apply:
If the
O_NDELAY or O_NONBLOCK file status flag is set:
If nbyte is less than or equal to PIPSIZ and sufficient room exists in the pipe or
FIFO, the
write() succeeds and returns the number of bytes written;
If nbyte is less than or equal to PIPSIZ but insufficient room exists in the pipe or
FIFO, the
write() returns having written nothing. If O_NONBLOCK is set, -1 is returned and errno
is set to [EAGAIN]. If O_NDELAY is set, 0 is returned.
If nbyte is greater than PIPSIZ and the pipe or FIFO is full, the write returns having written
nothing. If O_NONBLOCK is set, -1 is returned and errno is set to [EAGAIN]. If O_NDELAY
is set, 0 is returned.
If nbyte is greater than PIPSIZ, and some room exists in the pipe or FIFO, as much data as fits
in the pipe or FIFO is written, and write() returns the number of bytes actually written, an
amount less than the number of bytes requested.
If the O_NDELAY and O_NONBLOCK file status flags are clear:
The write() always executes correctly (blocking as necessary), and returns the number of
bytes written.
For character special devices, if the stopio() call was used on the same device after it was opened,
write() returns -1, sets errno to [EBADF], and issues the SIGHUP signal to the process.
write() clears the potential and granted privilege vectors on the file.
If the write is performed by any user other than the owner or a user who has appropriate privileges,
write() clears the set-user-ID, set-group-ID, and sticky bits on all nondirectory files. If the write is per-
formed 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.
ERRORS
If write() or writev() fails, the file offset remains unchanged and errno is set to one of the follow-
ing values.
[EAGAIN] Enforcement-mode file and record locking was set, O_NDELAY was set, and there was
a blocking record lock.
Section 2−−484 Hewlett-Packard Company − 1 − HP-UX 11i Version 1: September 2005