CLOSEDIR(3POSIX)
π« closedir(3POSIX) β bestie's guide to closing a directory stream π«
okay so this page is from the POSIX Programmer's Manual (that's the manual name, we're folding it in here, you're welcome) and it's all about closedir(). IEEE/The Open Group put it out, 2017 vintage, iconic behavior honestly.
πΈ PROLOG πΈ
Real talk before we even start: this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ β so if you're on Linux, pls go consult the corresponding Linux manual page for the deets on Linux behavior. Orrr the interface may not be implemented on Linux at all. So like. Vibe check your platform first, bestie. π«Ά
β¨ NAME β¨
closedir β close a directory stream. that's it. that's the whole job. π
π SYNOPSIS π
#include <dirent.h>
int closedir(DIR *dirp);
π¦ DESCRIPTION π¦
okay so the closedir() function shall close the directory stream referred to by the argument dirp. π§
Upon return, the value of dirp may no longer point to an accessible object of the type DIR. so like, don't go touching it afterwards, that's giving chaos. π
And if a file descriptor is used to implement type DIR, that file descriptor shall be closed. bye bye fd, you served. π
β RETURN VALUE β
Upon successful completion, closedir() shall return 0. π
Otherwise, -1 shall be returned and errno set to indicate the error. not the slay we wanted but okay, read your errno. π
π₯ ERRORS π₯
The closedir() function may fail if:
EBADFβ thedirpargument does not refer to an open directory stream. like bestie, that stream is not open. it's not. πEINTRβ theclosedir()function was interrupted by a signal. rude of the signal honestly.
The following sections are informative.
πΈ EXAMPLES πΈ
Closing a Directory Stream π
The following program fragment demonstrates how the closedir() function is used. look at her go:
...
DIR *dir;
struct dirent *dp;
...
if ((dir = opendir (".")) == NULL) {
...
}
while ((dp = readdir (dir)) != NULL) {
...
}
closedir(dir);
...
open the dir, loop through the entries, close the dir. that's the whole arc. main character energy from start to finish. β¨
π APPLICATION USAGE π
None.
ngl there is literally nothing here. moving on. π«Ά
π RATIONALE π
None.
also nothing. the committee said no thoughts, head empty. π
π FUTURE DIRECTIONS π
None.
nothing coming down the pipeline either. she's stable, she's timeless, she's closedir(). β
π SEE ALSO π
dirfd()fdopendir()
The Base Definitions volume of POSIX.1β2017, <dirent.h>
π COPYRIGHT π
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page, bestie!! ππ shoutout to IEEE/The Open Group, 2017 for bringing us this absolute banger of a syscall wrapper. close your directory streams, kids. periodt. π β¨π
π¦ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 Β· Other
- debian trixie: manpages-posix-dev 2017a-2 Β· Other
- ubuntu jammy: manpages-posix-dev 2017a-2 Β· Other
- ubuntu noble: manpages-posix-dev 2017a-2 Β· Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms