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_ino is an inode number.
  • d_offset is the distance from the start of the directory to this old_linux_dirent.
  • d_reclen is the size of d_name, not counting the terminating null byte ('\0').
  • d_name is a null-terminated filename.

๐Ÿซถ RETURN VALUE ๐Ÿซถ

  • On success, 1 is returned. (one entry. one. singular. we're not greedy.)
  • On end of directory, 0 is returned.
  • On error, -1 is returned, and errno is set to indicate the error.

๐Ÿ”ฅ ERRORS ๐Ÿ”ฅ

  • EBADF โ€” Invalid file descriptor fd.
  • 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
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms