opendir - open a directory
#include <sys/types.h> #include <dirent.h> DIR *opendir(const char *dirname);
The opendir() function opens a directory stream corresponding to the directory named by the dirname argument..
Upon successful completion, opendir() returns a pointer to an object of type DIR. Otherwise, a null pointer is returned and errno is set to indicate the error.
The opendir() function will fail if:
- [EACCES]
- Search permission is denied for the component of the path prefix of dirname or read permission is denied for dirname.
- [ELOOP]
- Too many symbolic links were encountered in resolving path.
- :
- [EMFILE]
- {OPEN_MAX} file descriptors are currently open in the calling process.
- [ENAMETOOLONG]
- Pathname resolution of a symbolic link produced an intermediate result whose length exceeds {PATH_MAX}.
- [ENFILE]
- Too many files are currently open in the system.
None.
The opendir() function should be used in conjunction with readdir(), closedir() and rewinddir() to examine the contents of the directory (see the EXAMPLES section in readdir()). This method is recommended for portability.
None.
closedir(), lstat(), readdir(), rewinddir(), symlink(), <dirent.h>, <limits.h>, <sys/types.h>.