getdirentries(3)
π¦ getdirentries β ok bestie let's talk directory entries π¦
So this is a page from the Library Functions Manual β the getdirentries(3) one. It's a whole vibe, it's a classic, and honestly you probably don't need it, but we're gonna learn it anyway because I love you. π
β¨ NAME β¨
getdirentries β get directory entries in a filesystem-independent format
Like. It reads dir entries. Filesystem-agnostic. Iconic behavior, lowkey.
π LIBRARY π
Standard C library (libc, -lc)
That's your link line bestie, <green>-lc</green>. Periodt.
πΈ SYNOPSIS πΈ
#include <dirent.h>
ssize_t getdirentries(size_t size;
int fd, char buf[restrict size], size_t size,
off_t *restrict basep);
β οΈ bestie look at that synopsis real close before you go typing it at a compiler, okay? write it down character for character, do not freestyle. π
π Feature Test Macro Requirements for glibc π (go read feature_test_macros(7) if you want the full tea)
getdirentries():
Since glibc 2.19:
_DEFAULT_SOURCE
glibc 2.19 and earlier:
_BSD_SOURCE || _SVID_SOURCE
So like β new glibc, just _DEFAULT_SOURCE. Old glibc? You need _BSD_SOURCE or _SVID_SOURCE. The way that glibc gates features behind macrosβ¦ it's giving β¨gatekeeperβ¨ but we move.
π DESCRIPTION π
Okay so here's what it actually does, no cap:
- It reads directory entries from the directory specified by
fdand shoves them intobuf. π₯ - At most
sizebytes get read. That's your ceiling, that's the cap, respect it. π - Reading starts at offset
*basepπ - and
*basepgets updated with the new position after the read. π
So it's like a cursor you hand over and it hands back, moved forward. Cute. Productive. Main character energy. π
β RETURN VALUE β
- On success:
getdirentries()returns the number of bytes read, or zero when you've hit the end of the directory. π (zero = "that's all folks", not an error, don't panic) - On error: -1 is returned, and
errnois set to tell you what went wrong. π
π ERRORS π
See the Linux library source code for details.
That's it. That's the whole section. It literally says go read the source. It's giving "figure it out bestie" and honestly? Respect. π₯
π ATTRIBUTES π
For an explanation of the terms used in this section, see attributes(7). (The original lays this out as a table, but we're doing bullets because tables are not the vibe here.)
getdirentries()β Thread safety: MT-Safe π§΅β¨
(yes that's the only row, she's a simple girl, she's safe across threads, we love her)
π STANDARDS π
BSD.
One word. No notes. She said it. π©·
π§ NOTES π§
Use opendir(3) and readdir(3) instead.
FR FR bestie β this page is telling you to useopendir(3)andreaddir(3)instead. That's the actual manpage talking, not me. Take the hint. π
π₯ SEE ALSO π₯
okay that's the whole page, you ate that, go forth and read directories responsibly π«ΆπΈ
this has been Linux man-pages 6.20, dated 2026-02-08 β signing off, ily, bye bestie πβ¨
π¦ 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 1993, Rickard E. Faith <faith@cs.unc.edu>
- Copyright 1991-1992, Free Software Foundation
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms