1CLOSEDIR(3P) POSIX Programmer's Manual CLOSEDIR(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
12 closedir — close a directory stream
13
15 #include <dirent.h>
16
17 int closedir(DIR *dirp);
18
20 The closedir() function shall close the directory stream referred to by
21 the argument dirp. Upon return, the value of dirp may no longer point
22 to an accessible object of the type DIR. If a file descriptor is used
23 to implement type DIR, that file descriptor shall be closed.
24
26 Upon successful completion, closedir() shall return 0; otherwise, -1
27 shall be returned and errno set to indicate the error.
28
30 The closedir() function may fail if:
31
32 EBADF The dirp argument does not refer to an open directory stream.
33
34 EINTR The closedir() function was interrupted by a signal.
35
36 The following sections are informative.
37
39 Closing a Directory Stream
40 The following program fragment demonstrates how the closedir() function
41 is used.
42
43
44 ...
45 DIR *dir;
46 struct dirent *dp;
47 ...
48 if ((dir = opendir (".")) == NULL) {
49 ...
50 }
51
52 while ((dp = readdir (dir)) != NULL) {
53 ...
54 }
55
56 closedir(dir);
57 ...
58
60 None.
61
63 None.
64
66 None.
67
69 dirfd(), fdopendir()
70
71 The Base Definitions volume of POSIX.1‐2017, <dirent.h>
72
74 Portions of this text are reprinted and reproduced in electronic form
75 from IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
76 table Operating System Interface (POSIX), The Open Group Base Specifi‐
77 cations Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of
78 Electrical and Electronics Engineers, Inc and The Open Group. In the
79 event of any discrepancy between this version and the original IEEE and
80 The Open Group Standard, the original IEEE and The Open Group Standard
81 is the referee document. The original Standard can be obtained online
82 at http://www.opengroup.org/unix/online.html .
83
84 Any typographical or formatting errors that appear in this page are
85 most likely to have been introduced during the conversion of the source
86 files to man page format. To report such errors, see https://www.ker‐
87 nel.org/doc/man-pages/reporting_bugs.html .
88
89
90
91IEEE/The Open Group 2017 CLOSEDIR(3P)