HP-UX Reference (11i v2 04/09) - 2 System Calls (vol 5)

w
write(2) write(2)
[ENOSPC] Not enough space on the file system. The process does not possess the
limit
effective privilege to override this restriction.
[ENXIO] A request was made of a non-existent device, or the request was outside the capabil-
ities of the device.
[ENXIO] A hangup occurred on the
STREAM
being written to.
[EPIPE] An attempt is made to write to a pipe or FIFO that is not open for reading by any
process, or that only has one end open. A
SIGPIPE signal will also be sent to the
process.
[ERANGE] The transfer request size was outside the range supported by the
STREAMS file
associated with fildes.
Under the following conditions,
writev() fails and sets
errno to:
[EFAULT] iov_base or iov points outside of the allocated address space. The reliable detection
of this error is implementation dependent.
[EINVAL] One of the iov_len values in the iov array is negative.
[EINVAL] The sum of the iov_len values in the iov array would overflow an ssize_t .
Under the following conditions, the
writev() function may fail and set errno to:
[EINVAL] The iovcnt argument was less than or equal to 0, or greater than
{IOV_MAX}.
Under the following conditions, the
pwrite() function fails, the file pointer remains unchanged and
errno is set to:
[EINVAL] The offset argument is invalid, and the value is negative.
[ESPIPE] The fildes argument is associated with a pipe or FIFO.
Under the following conditions, write() or writev() fails, the file offset is updated to reflect the
amount of data transferred and errno is set to:
[EFAULT] buf points outside the process’s allocated address space. The reliable detection of
this error is implementation dependent.
EXAMPLES
Assuming a process opened a file for writing, the following call to
write() attempts to write mybufsize
bytes to the file from the buffer to which mybuf points.
#include <string.h>
int fildes;
size_t mybufsize;
ssize_t nbytes;
char *mybuf = "aeiou and sometimes y";
mybufsize = (size_t)strlen (mybuf);
nbytes = write (fildes, (void *)mybuf, mybufsize);
WARNINGS
Check signal (5) for the appropriateness of signal references on systems that support sigvector(). See
the sigvector (2) manpage.
sigvector() can affect the behavior of the write(), writev() and pwrite() functions described here.
Character special devices, and raw disks in particular, apply constraints on how
write() can be used.
See specific Section 7 manual entries for details on particular devices.
AUTHOR
write() was developed by HP, AT&T, and the University of California, Berkeley.
SEE ALSO
mkfs(1M), chmod(2), creat(2), dup(2), fcntl(2), getrlimit(2), lockf(2), lseek(2), open(2), pipe(2), sigvec-
tor(2), ulimit(2), ustat(2), signal(5), <limits.h>, <stropts.h>, <sys/uio.h>, <unistd.h>.
HP-UX 11i Version 2: September 2004 4 Hewlett-Packard Company Section 2497