pwrite
pwrite is a seekable-file operation that writes up to the requested byte count at an explicit offset without changing the open file description's current offset.
A successful call may transfer fewer bytes than requested. Linux man-pages documents the historical O_APPEND exception: data is appended despite the explicit position. [1] This is not universal across current C libraries: the musl 1.2.6 release announcement reports correction of the append-mode case using RWF_NOAPPEND and reports an error on older kernels instead of silently writing at the wrong position. [2] Linux documents RWF_NOAPPEND for pwritev2 since 6.9. Record the library, kernel and filesystem when testing. [3]
Relations
- related
- short-write, o-append, open-file-description, fsync, rwf-atomic
Advantages
- Separates write positioning from a shared current-offset cursor.
Limitations
- Does not serialize overlapping writers or promise full-length, untorn or durable completion.
- The documented Linux append exception and library workarounds need environment-specific checks.
Citations
- Linux man-pages 6.19: pread(2), positional writes and O_APPEND exception
- musl 1.2.6 release announcement: pwrite correction and older-kernel fallback
- Linux man-pages 6.19: readv(2), RWF_APPEND and RWF_NOAPPEND