readdir(2)
๐ readdir(2) โ the system call manual page, bestie edition ๐
okay so. before we even start. this is readdir(2), from the System Calls Manual, and I need you to sit down for this one because it's giving "why does this page even exist" energy. not in a bad way!! more like a museum exhibit way. a little fossil. a lil historical artifact. we love her for the lore. ๐ฆ
โจ NAME โจ
readdir โ read a directory entry. that's it. that's the whole job description.
๐ LIBRARY ๐
Standard C library (libc, -lc). the usual queen.
๐ SYNOPSIS ๐
#include <sys/syscall.h> /* Definition of SYS_* constants */
#include <unistd.h>
int syscall(SYS_readdir, unsigned int fd,
struct old_linux_dirent *dirp, unsigned int count);
Note: There is no definition of struct old_linux_dirent; see VERSIONS.
like. they didn't even give you the struct. you have to build her yourself. diy era ๐ (VERSIONS explains, don't panic)
๐ธ DESCRIPTION ๐ธ
okay bestie, I'm gonna hold your hand while I say this: this is not the function you are interested in. ๐ญ
Look at readdir(3) for the POSIX conforming C library interface. This page documents the bare kernel system call interface, which is superseded by getdents(2). so like... you're reading the prequel. the origin story nobody asked for. no cap.
readdir() reads one old_linux_dirent structure from the directory referred to by the file descriptor fd into the buffer pointed to by dirp. The argument count is ignored โ at most one old_linux_dirent structure is read. (yes girl, they pass it in and then just. don't use it. iconic behavior honestly.)
The old_linux_dirent structure is declared (privately in Linux kernel file fs/readdir.c) as follows:
struct old_linux_dirent {
unsigned long d_ino; /* inode number */
unsigned long d_offset; /* offset to this old_linux_dirent */
unsigned short d_namlen; /* length of this d_name */
char d_name[1]; /* filename (null-terminated) */
}
let's break the fields down, one by one, because each one is doing its own lil thing:
d_inois an inode number.d_offsetis the distance from the start of the directory to thisold_linux_dirent.d_reclenis the size ofd_name, not counting the terminating null byte ('\0').d_nameis a null-terminated filename.
๐ซถ RETURN VALUE ๐ซถ
- On success,
1is returned. (one entry. one. singular. we're not greedy.) - On end of directory,
0is returned. - On error,
-1is returned, anderrnois set to indicate the error.
๐ฅ ERRORS ๐ฅ
EBADFโ Invalid file descriptorfd.EFAULTโ Argument points outside the calling process's address space.EINVALโ Result buffer is too small.ENOENTโ No such directory.ENOTDIRโ File descriptor does not refer to a directory.
๐ VERSIONS ๐
You will need to define the old_linux_dirent structure yourself. However, probably you should use readdir(3) instead. (the subtle shade of "probably" is sending me ngl)
This system call does not exist on x86-64. not a thing. never was, for you. if you're on a modern 64-bit box and you're hunting for it, go touch some grass, it's not there, bestie. ๐ง
๐ STANDARDS ๐
Linux. just Linux. everyone else said "no thank you" and honestly? fair.
๐ SEE ALSO ๐
getdents(2)โ the glow-up. the successor. use this one.readdir(3)โ the POSIX-conforming one you actually want. go here. fr fr.
and that's the whole page!! you made it to the end of the fossil exhibit, I'm so proud of you ๐ฅน go forth and call readdir(3) like a normal person, ok? mwah ๐
this lil artifact is from Linux man-pages 6.20, dated 2026-02-08 โ shoutout to the man-pages girlies for keeping the receipts ๐ โจ
๐ฆ 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 1995, Andries E. Brouwer <aeb@cwi.nl>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms