CLOSEDIR(3P)

πŸ’– CLOSEDIR(3P) πŸ’–

okay bestie, so this one is from the POSIX Programmer's Manual β€” that's the 3P part of the name, iykyk. We're talking the standard itself, not the Linux remix. πŸŽ€

Heads up fr fr: the Linux implementation of this interface may differ (go check the corresponding Linux manual page for details on Linux behavior), or the interface might not even be implemented on Linux at all. πŸ’€

✨ PROLOG ✨

This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux.


🌸 NAME 🌸

closedir β€” close a directory stream. literally that's the whole job, and she does it flawlessly πŸ‘‘


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <dirent.h>

int closedir(DIR *dirp);

πŸ’… DESCRIPTION πŸ’…

So the closedir() function shall close the directory stream that dirp is pointing at. Yes, that dirp argument, the one right there in the signature, her. 🫢

Once you come back from the call, dirp might not point to an accessible object of type DIR anymore β€” like, the whole vibe is gone, don't go poking at it. πŸ‘‹

And if a file descriptor is used to implement type DIR? Then that file descriptor shall be closed too. Two-for-one cleanup, we love a thorough queen. ✨


πŸ’œ RETURN VALUE πŸ’œ

  • Success β€” closedir() shall return 0. Slay.
  • Failure β€” -1 shall be returned, and errno gets set to indicate the error. πŸ™ˆ

😭 ERRORS 😭

The closedir() function may fail if:

  • EBADF β€” the dirp argument does not refer to an open directory stream. bestie. she's not open. stop it. πŸ’€
  • EINTR β€” the closedir() function was interrupted by a signal. rude, honestly.

The following sections are informative. (translation: the lore continues, but this is bonus content ✨)


πŸŽ€ EXAMPLES πŸŽ€

Closing a Directory Stream

Here's a little program fragment showing how the closedir() function gets used. No cap, this is the whole move:

...
    DIR *dir;
    struct dirent *dp;
...
    if ((dir = opendir (".")) == NULL) {
...
    }

    while ((dp = readdir (dir)) != NULL) {
...
    }

    closedir(dir);
...

open it, read it, close it, periodt. 🌈


🌟 APPLICATION USAGE 🌟

None. (yes really, nothing. iconic minimalism πŸ’…)


🧚 RATIONALE 🧚

None. (also nothing. she simply is.)


⭐ FUTURE DIRECTIONS ⭐

None. she's not going anywhere, she's booked and busy forever. πŸ‘‘


πŸ”₯ 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 πŸ’– this was IEEE/The Open Group, 2017 β€” CLOSEDIR(3P), signing off. go close your directory streams responsibly, ily 🫢✨

πŸ“¦ where this page comes from