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, anderrnogets set to tell you what went wrong π
π ERRORS π
EBADFβ Invalid directory stream descriptordirp. 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: afterclosedir(), thatdirpis 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
- Copyright 1993, David Metcalfe <david@prism.demon.co.uk>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms