READ(3)
π NAME π
okay so bestie, welcome to the read(3) page π
this is the Library Functions Manual tea, and the icons are read, readn, write, pread, and pwrite β all about reading or writing a file. periodt.
β¨ SYNOPSIS β¨
#include <u.h>
#include <libc.h>
long read(int fd, void *buf, long nbytes)
long readn(int fd, void *buf, long nbytes)
long write(int fd, void *buf, long nbytes)
long pread(int fd, void *buf, long nbytes, vlong offset)
long pwrite(int fd, void *buf, long nbytes, vlong offset)
π¦ DESCRIPTION π¦
read reads nbytes bytes of data from the offset in the file associated with fd into memory at buf β¨ the offset is advanced by the number of bytes read. And no cap, it is not guaranteed that all nbytes bytes will be read β for example, if the file refers to the console, at most one line will be returned. In any event, the number of bytes read is returned. A return value of 0 is conventionally interpreted as end of file π
readn is just like read, but it does successive read calls until nbytes have been read, or a read system call returns a non-positive count. it's giving βkeep asking until the vibe check says stopβ π«Ά
write writes nbytes bytes of data starting at buf to the file associated with fd at the file offset π the offset is advanced by the number of bytes written. The number of characters actually written is returned.
bestie, it should be regarded as an error if this is not the same as requested π like, do not let that slide.
pread and pwrite are equivalent to a seek(3) to offset followed by a read or write πΈ by combining the operations in a single atomic call, they more closely match the 9P protocol (see intro(9p)) and β more important β permit multiprocess programs to execute multiple concurrent read and write operations on the same file descriptor without interference. iconic atomic behavior, no notes π
π SOURCE π
/src/lib9/readn.c β that's the source file, bestie π
π SEE ALSO π
π¨ DIAGNOSTICS π¨
These functions set errstr π so yeah, the diagnostics are right there in errstr.
okay bye bestie π this pageβs footer is the READ(3) line from the Library Functions Manual β no extra version or date line on this one, so thatβs the whole cute sign-off πβ¨
π¦ where this page comes from
- alpine 3.24: plan9port-doc 0_git20260208-r0 Β· LPL-1.02
- arch rolling: plan9port 20261021-2 Β· custom
- nixos 26.05: plan9port 0-unstable-2025-11-10
- nixos 26.05: plan9port-wayland 0-unstable-2025-11-26
- nixpkgs unstable: plan9port 0-unstable-2025-11-10
- nixpkgs unstable: plan9port-wayland 0-unstable-2025-11-26
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms