READ(3)

πŸ“¦
version 0_git20260208 Β· 5 versions
, in alpine 3.24, arch rolling, nixos 26.05, nixpkgs unstable

πŸ’– 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 πŸŽ€βœ¨