FAT | RFS | XFS | ZFS
opendir()
PROTOTYPE
#include <posix.h>
DIR *opendir(const char *path);
DESCRIPTION
opendir() allocates a file control block and associates it with the directory specified by path. Paths starting with ‘/’ are absolute. Otherwise they are relative to the CWD. The directory’s current position in its entry list is set to the first entry
The caller needs search-access to the path prefix and read-access to the specified directory.
If successful, opendir() returns an opaque directory handle that can be used by readdir() and the related readdir_fopen(), readdir_open(), and readdir_stat() to access the directory’s file list. Otherwise, it sets errno and returns NULL.
ERROR CODES
| EACCES | No execute access to a directory in the path prefix or no read access to the specified directory. |
| EFAULT | path equals NULL. |
| EMFILE | No file control block is free. FOPEN_MAX files are currently open. |
| ENAMETOOLONG | A name in path exceeds the effective maximum file name length. |
| ENOENT | path is the empty string or includes a directory that was not found. |
| ENOTDIR | One of the path components is not a directory. |
EXAMPLE
/*-------------------------------------------------------------*/
/* Open directory associated with path1. */
/*-------------------------------------------------------------*/
cur_dir = opendir(path1);
if (cur_dir == NULL)
{
perror("openddir() failed");
return -1;
}