pread(2)
π pread(2) β the system call manual, but make it cute π
okay bestie, welcome to the System Calls Manual page for pread(2) β¨ this is the Linux man-pages version, and we're gonna get you so comfy with it. grab a boba, sit down, let's go π§π
β¨ NAME β¨
pread, pwrite β read from or write to a file descriptor at a given offset π―
so like. you read or you write. but at a specific offset. the way that's iconic honestly π
π LIBRARY π
Standard C library (libc, -lc) π«Ά
πΈ SYNOPSIS πΈ
#include <unistd.h>
ssize_t pread(size_t count;
int fd, void buf[count], size_t count,
off_t offset);
ssize_t pwrite(size_t count;
int fd, const void buf[count], size_t count,
off_t offset);
π Feature Test Macro Requirements for glibc π
(see feature_test_macros(7))
pread(),pwrite():_XOPEN_SOURCE >= 500|| /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L
like, if you want these bad boys you GOTTA define the right macros first, it's giving β¨gatekeepingβ¨ but whatever, that's just how glibc is π
π¦ DESCRIPTION π¦
pread() reads up to count bytes from file descriptor fd at offset offset (from the start of the file) into the buffer starting at buf. The file offset is not changed. π that's the whole point, bestie, it does NOT touch your file offset, she's respectful like that.
pwrite() writes up to count bytes from the buffer starting at buf to the file descriptor fd at offset offset. The file offset is not changed. same energy, same slay π₯
the file referenced by fd must be capable of seeking. no seeking, no service, periodt π
ββοΈ
π« RETURN VALUE π«
on success, pread() returns the number of bytes read (and a return of zero means end of file, so don't panic π«Ά) and pwrite() returns the number of bytes written β
ngl it is not an error for a successful call to transfer fewer bytes than you asked for β check read(2) and write(2) for the full tea β
on error, -1 is returned and errno is set to indicate the error π
π ERRORS π
pread()can fail and seterrnoto any error specified forread(2)orlseek(2).pwrite()can fail and seterrnoto any error specified forwrite(2)orlseek(2).
like, it's not giving you a custom error list, it's borrowing from its friends. iykyk π
π STANDARDS π
POSIX.1-2024. certified, official, main character energy fr fr π
π HISTORY π
POSIX.1-2001. the origin story π¬
added in Linux 2.1.60; the entries in the i386 system call table were added in Linux 2.1.69. C library support (including emulation using lseek(2) on older kernels without the system calls) was added in glibc 2.1. so she's been around a minute, a real veteran π«‘
π§ C library/kernel differences π§
on Linux, the underlying system calls were renamed in Linux 2.6: pread() became pread64(), and pwrite() became pwrite64(). The system call numbers remained the same. the glibc pread() and pwrite() wrapper functions transparently deal with the change β¨ lowkey magic.
on some 32-bit architectures, the calling signature for these system calls differ, for the reasons described in syscall(2). noted π
β NOTES β
the pread() and pwrite() system calls are especially useful in multithreaded applications. they let multiple threads perform I/O on the same file descriptor without being affected by changes to the file offset by other threads π§΅β¨
like no cap, this is THE reason to use them. your threads stop fighting over one shared offset and honestly? peace at last ποΈ
π BUGS π
POSIX requires that opening a file with the O_APPEND flag should have no effect on the location at which pwrite() writes data. However, on Linux, if a file is opened with O_APPEND, pwrite() appends data to the end of the file, regardless of the value of offset. π
β οΈ bestie listen to me. on Linux,O_APPENDwill OVERRIDE youroffsetinpwrite(). your carefully calculated offset? ignored. she's appending. do NOT get caught lacking by this one π
π SEE ALSO π
that's the whole page babes, go forth and pread() responsibly π¦β¨
this manual page came from Linux man-pages 6.20, dated 2026-02-08, and the page is, obviously, pread(2) πΈ mwah, bye bestie ππ
π
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π the page's license: Linux-man-pages-copyleft
- Copyright 1999, Joseph Samuel Myers <jsm28@cam.ac.uk>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms