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 β€” the dirp argument does not refer to an open directory stream. like bestie, that stream is not open. it's not. πŸ’€
  • EINTR β€” the closedir() 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>


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. πŸ’…βœ¨πŸŒˆ