closedir(3)

closedir(3) β€” bestie, it's time to let go πŸ’…

okay so you opened a directory, you had your little look around, and now?? you gotta say bye πŸ₯Ί that's literally what closedir is for. it's giving "leave the group chat cleanly." she's a <pink>Library Functions Manual</pink> girlie, living in the Standard C library (libc, -lc), and she's about to become your best friend.


✨ NAME ✨

closedir β€” close a directory πŸšͺπŸ’–


πŸ“š LIBRARY πŸ“š

Standard C library (libc, -lc).

like, that's the one you already have, no cap.


🌸 SYNOPSIS 🌸

#include <sys/types.h>
#include <dirent.h>

int closedir(DIR *dirp);

look at her. two includes, one tiny function call. iconic behavior.


πŸ¦‹ DESCRIPTION πŸ¦‹

so the closedir() function closes the directory stream that's chillin' in dirp. that's the whole job. she's focused.

but wait, there's more β€” a successful call to closedir() also closes the underlying file descriptor associated with dirp. yeah, she does both. multitasking queen πŸ‘‘

and after this call? the directory stream descriptor dirp is not available anymore. like, gone. done. no take-backs, no second chances. do not touch it, bestie. that pointer is a ghost now πŸ’€


🌈 RETURN VALUE 🌈

  • <green>0</green> on success β€” she ate and left no crumbs ✨
  • <red>-1</red> on error, and errno gets set to tell you what went wrong 😭

πŸŽ€ ERRORS πŸŽ€

  • EBADF β€” Invalid directory stream descriptor dirp. bestie... that's not a real directory stream. i'm not mad, i'm just disappointed 🫢

πŸ‘‘ ATTRIBUTES πŸ‘‘

ngl, for an explanation of the terms used in this section you should peek at attributes(7). but here's the tea:

  • Interface: closedir() β€” Attribute: Thread safety β€” Value: MT-Safe

so she's <mint>MT-Safe</mint>, meaning multiple threads can vibe with her at the same time, no drama. slay.


⭐ STANDARDS ⭐

POSIX.1-2008. certified. official. she's on the list πŸ’œ


🧚 HISTORY 🧚

POSIX.1-2001, SVr4, 4.3BSD. she's been around, she's got lore, she's a legacy queen and we respect her for it πŸ•°οΈβœ¨


πŸ”₯ SEE ALSO πŸ”₯

the whole directory-stream friend group fr fr 🫢


reminder bestie: after closedir(), that dirp is toast. don't dereference it, don't pass it around, don't think about it. vibe check failed on that pointer 😭

that's the whole page, and if you wanna cite your sources it's Linux man-pages 6.20, dated 2026-02-08 β€” so go forth, close your directories, and remember: cleanup is self-care πŸ’–πŸŒΈ no cap.

πŸ“¦ 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