SYNOPSIS
#include <unistd.h>
ssize_t pwrite(int fildes, const void *buf, size_t nbyte, off_t offset);
ssize_t pwrite64(int fildes, const void *buf, size_t nbyte, off64_t offset);
ssize_t write(int fildes, const void *buf, size_t nbyte);
DESCRIPTION
The
If the number of bytes is 0,
On a regular file or other file
capable of seeking, the actual writing of data proceeds from the
position in the file indicated by the file offset associated with
the specified file descriptor. Before successful return from
On a file not capable of seeking, writing always takes place starting at the current position. The value of a file offset associated with such a device is undefined.
If the O_APPEND flag is set for the file descriptor, the file offset is set to the end of the file prior to each write and no intervening file modification operation occurs between changing the file offset and the write operation.
If a
If
Writes larger than SSIZE_MAX are unsupported.
After a
- Any successful
read() from each byte position in the file that was modified by that write returns the data specified by thewrite() for that position until such byte positions are again modified. - Any subsequent
write() to the same byte position in the file overwrites that file data.
Write requests to a pipe or FIFO are handled the same as a regular file with the following exceptions:
- There is no file offset associated with a pipe, hence each write request appends to the end of the pipe.
- Write requests of PIPE_BUF bytes or less are not interleaved with data from other processes doing writes on the same pipe. Writes of greater than PIPE_BUF bytes may have data interleaved, on arbitrary boundaries, with writes by other processes, whether or not the O_NONBLOCK flag is set.
- If the O_NONBLOCK flag is clear, a write request may cause the thread to block, but on normal completion, it returns the request size, indicating that all data has been written.
- If the O_NONBLOCK flag is set,
write() requests are handled as follows:- The
write() function does not block the thread. - For a write
request of PIPE_BUF or fewer bytes, if
there is sufficient space available in the pipe,
write() transfers all the data and returns the number of bytes requested. Otherwise,write() transfers no data and returns -1 with errno set to EAGAIN. - For a write
request of more than PIPE_BUF bytes, when at least
one byte can be written, as much data as possible
is transferred, and the number of bytes
written is returned. Otherwise, no data is
transferred, and
write() returns -1 with errno set to EAGAIN.
- The
When attempting to write to a file descriptor (other than a pipe or FIFO) that supports non-blocking writes and cannot accept data immediately:
- If the O_NONBLOCK flag is clear,
write() blocks the calling thread until data can be accepted. - If the O_NONBLOCK flag is set,
write() does not block the process. If some data can be written without blocking the process,write() writes what it can and return the number of bytes written. Otherwise, it returns -1 with errno set to EAGAIN.
If the O_SYNC bit has been set, write I/O operations on the file descriptor complete only after the data has been flushed to the mass storage device.
Upon successful completion, when the number of requested bytes is greater
than 0,
The
The
PARAMETERS
- fildes
-
Is the file descriptor of an open file to write to.
- buf
-
Is an array of data to write to the open file.
- nbyte
-
Is the number of bytes to write to the file.
- offset
-
Specifies the point in the file where
pwrite() orpwrite64() begins writing.
RETURN VALUES
If successful, these functions return the number of bytes written to the open file descriptor fildes. The number of bytes written never exceeds nbyte. Otherwise, these functions return -1 and set errno to one of the following values:
- EAGAIN
-
The O_NONBLOCK flag is set for the file descriptor and the thread would be delayed in the
write() operation. - EBADF
-
The fildes parameter is not a valid file descriptor open for writing.
- EFAULT
-
The buf parameter is not a valid pointer.
- EFAULT
-
buf points outside the allocated address space of the process.
- EFBIG
-
An attempt is made to write a file that exceeds the file size limit of the process.
- EFBIG
-
The file is a regular file, nbyte is greater than 0 and the starting position is greater than or equal to the offset maximum established in the open file description associated with fildes.
- EINTR
-
A signal interrupted the call to
write() ,pwrite() , orpwrite64() . - EIO
-
A physical I/O error has occurred.
- ENOMEM
-
Insufficient memory exists to complete the request.
- ENOSPC
-
There is no more free space on the device that fildes refers to.
- ENXIO
-
A request was made of a non-existent device, or the request was outside the capabilities of the device.
- EOVERFLOW
-
For
pwrite() andpwrite64() , the specified offset would cause a write beyond the 2 GB boundary. - EPIPE
-
An attempt is made to write to a pipe or FIFO that is not open for reading by any process, or that has only one end open. A SIGPIPE is also sent to the thread.
CONFORMANCE
POSIX.1 (1996), with exceptions. UNIX 03, with exceptions.
MULTITHREAD SAFETY LEVEL
Async-signal-safe.
PORTING ISSUES
Refer to File Management in the Windows Concepts chapter of the PTC MKS Toolkit UNIX to Windows Porting Guide for a detailed discussion of file handling, including a discussion of text mode and binary mode for files.
The test which causes the EFBIG error condition to be returned
can be disabled by using the
While the UNIX 03 specification states that
AVAILABILITY
PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition
SEE ALSO
- Functions:
creat() ,dup() ,dup2() ,fcntl() ,ioctl() ,open() ,pipe() ,read() ,readv() ,socket() ,writev()
- Miscellaneous:
- lf64
PTC MKS Toolkit 10.5 Documentation Build 40.