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);
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.
Writes larger than SSIZE_MAX are unsupported.
- Any successful
read()from each byte position in the file that was modified by that write returns the data specified by the write()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:
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
write()returns -1 with errno set to EAGAIN.
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
Is the file descriptor of an open file to write to.
Is an array of data to write to the open file.
Is the number of bytes to write to the file.
Specifies the point in the file where
pwrite()or pwrite64()begins writing.
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:
The O_NONBLOCK flag is set for the file descriptor and the thread would be delayed in the
The fildes parameter is not a valid file descriptor open for writing.
The buf parameter is not a valid pointer.
buf points outside the allocated address space of the process.
An attempt is made to write a file that exceeds the file size limit of the process.
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.
A signal interrupted the call to
write(), pwrite(), or pwrite64().
A physical I/O error has occurred.
Insufficient memory exists to complete the request.
There is no more free space on the device that fildes refers to.
A request was made of a non-existent device, or the request was outside the capabilities of the device.
pwrite()and pwrite64(), the specified offset would cause a write beyond the 2 GB boundary.
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.
POSIX.1 (1996), with exceptions. UNIX 03, with exceptions.
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
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
creat(), dup(), dup2(), fcntl(), ioctl(), open(), pipe(), read(), readv(), socket(), writev()
PTC MKS Toolkit 10.1 patch 1 Documentation Build 2.