DIRREAD(3)
πΈ NAME πΈ
okay so this is the DIRREAD(3) page from the Library Functions Manual, and itβs all about dirread, dirreadall β read directory, bestie π
β¨
β¨ SYNOPSIS β¨
#include <u.h>
#include <libc.h>
long dirread(int fd, Dir **buf)
long dirreadall(int fd, Dir **buf)
#define STATMAX 65535U
#define DIRMAX (sizeof(Dir)+STATMAX)
π DESCRIPTION π
okay so picture this: the data you get back from a read(3) on a directory is a set of complete directory entries in a machine-independent format. Itβs exactly equivalent to the result of a stat(3) on each file or subdirectory in the directory. No cap. π«Ά
dirread decodes those directory entries into a machine-dependent form. It reads from fd and unpacks the data into an array of Dir structures. The address of that array is returned in *buf β and yeah, see stat(3) for the layout of a Dir. The array is allocated with malloc(3) each time dirread is called, so itβs fresh every single time β¨
dirreadall is like dirread, but it reads in the entire directory. By contrast, dirread steps through a directory one read(3) at a time β lil sips, not the whole thing π
Directory entries have variable length. A successful read of a directory always returns an integral number of complete directory entries; dirread always returns complete Dir structures. See read(9p) for more information β iykyk π
The constant STATMAX is the maximum size that a directory entry can occupy. The constant DIRMAX is an upper limit on the size necessary to hold a Dir structure and all the associated data. Basically: size limits, but make it iconic π
dirread and dirreadall return the number of Dir structures filled in buf. The file offset is advanced by the number of bytes actually read. slay. π
π SOURCE π
/src/lib9/dirread.c β thatβs the source file, bestie. π«Ά
π¦ SEE ALSO π¦
π DIAGNOSTICS π
dirread and dirreadall return zero for end of file and a negative value for error. In either case, *buf is set to nil, so the pointer can always be freed with impunity. No cap β free it and donβt stress. π«Ά
These functions set errstr. So if something goes sideways, check errstr, bestie. π¨
and thatβs the whole page, bestie β footer vibe is just DIRREAD(3) from the Library Functions Manual, no date printed on this one, so Iβm not inventing one. source/version? The source path is /src/lib9/dirread.c up in SOURCE, the manual name is DIRREAD(3), and thatβs periodt. πβ¨π
π¦ 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