1opendir(3)                 Library Functions Manual                 opendir(3)
2
3
4

NAME

6       opendir, fdopendir - open a directory
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <sys/types.h>
13       #include <dirent.h>
14
15       DIR *opendir(const char *name);
16       DIR *fdopendir(int fd);
17
18   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
19
20       fdopendir():
21           Since glibc 2.10:
22               _POSIX_C_SOURCE >= 200809L
23           Before glibc 2.10:
24               _GNU_SOURCE
25

DESCRIPTION

27       The  opendir()  function  opens a directory stream corresponding to the
28       directory name, and returns a pointer to  the  directory  stream.   The
29       stream is positioned at the first entry in the directory.
30
31       The  fdopendir()  function  is  like opendir(), but returns a directory
32       stream for the directory referred to by the open  file  descriptor  fd.
33       After  a  successful  call to fdopendir(), fd is used internally by the
34       implementation, and should not otherwise be used by the application.
35

RETURN VALUE

37       The opendir() and fdopendir() functions return a pointer to the  direc‐
38       tory  stream.  On error, NULL is returned, and errno is set to indicate
39       the error.
40

ERRORS

42       EACCES Permission denied.
43
44       EBADF  fd is not a valid file descriptor opened for reading.
45
46       EMFILE The per-process limit on the number of open file descriptors has
47              been reached.
48
49       ENFILE The system-wide limit on the total number of open files has been
50              reached.
51
52       ENOENT Directory does not exist, or name is an empty string.
53
54       ENOMEM Insufficient memory to complete the operation.
55
56       ENOTDIR
57              name is not a directory.
58

ATTRIBUTES

60       For an  explanation  of  the  terms  used  in  this  section,  see  at‐
61       tributes(7).
62
63       ┌────────────────────────────────────────────┬───────────────┬─────────┐
64Interface                                   Attribute     Value   
65       ├────────────────────────────────────────────┼───────────────┼─────────┤
66opendir(), fdopendir()                      │ Thread safety │ MT-Safe │
67       └────────────────────────────────────────────┴───────────────┴─────────┘
68

STANDARDS

70       POSIX.1-2008.
71

STANDARDS

73       opendir()
74              SVr4, 4.3BSD, POSIX.1-2001.
75
76       fdopendir()
77              POSIX.1-2008.  glibc 2.4.
78

NOTES

80       Filename entries can be read from a directory stream using readdir(3).
81
82       The  underlying file descriptor of the directory stream can be obtained
83       using dirfd(3).
84
85       The opendir()  function  sets  the  close-on-exec  flag  for  the  file
86       descriptor  underlying  the DIR *.  The fdopendir() function leaves the
87       setting of the close-on-exec flag unchanged for  the  file  descriptor,
88       fd.   POSIX.1-200x  leaves  it unspecified whether a successful call to
89       fdopendir() will set the close-on-exec flag for  the  file  descriptor,
90       fd.
91

SEE ALSO

93       open(2),  closedir(3),  dirfd(3), readdir(3), rewinddir(3), scandir(3),
94       seekdir(3), telldir(3)
95
96
97
98Linux man-pages 6.05              2023-07-20                        opendir(3)
Impressum