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 fd and shoves them into buf. πŸ“₯
  • At most size bytes get read. That's your ceiling, that's the cap, respect it. πŸ›‘
  • Reading starts at offset *basep πŸ‘ˆ
  • and *basep gets 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 errno is 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 use opendir(3) and readdir(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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms