NAME
opendir, readdir, rewinddir, closedir, dirfd - directory operations

SYNOPSIS
#include <sys/types.h>
#include <sys/dir.h>

DIR *opendir(filename)
const char *filename;

struct direct *readdir(dirp)
DIR *dirp;

void rewinddir(dirp)
DIR *dirp;

int closedir(dirp)
DIR *dirp;

int dirfd(dirp)
DIR *dirp;

DESCRIPTION
Opendir opens the directory named by filename and associates a
directory stream with it. Opendir returns a pointer to be used to
identify the directory stream in subsequent operations. The
pointer NULL is returned if filename cannot be accessed, or if it
cannot malloc(3) enough memory to hold the whole thing.

Readdir returns a pointer to the next directory entry. It returns
NULL upon reaching the end of the directory or detecting an invalid
seekdir operation.

Rewinddir resets the position of the named directory stream to the
beginning of the directory.

Closedir closes the named directory stream and frees the structure
associated with the DIR pointer.

Dirfd returns the integer file descriptor associated with the named
directory stream, see open(2).

The telldir and seekdir operations are not currently supported
because there is no known way to efficiently implement them to
correctly handle all remote file systems such as NFS or AFS.

Sample code which searchs a directory for entry "name" is:

len = strlen(name);
dirp = opendir(".");
while ((dp = readdir(dirp)) != NULL)
if (dp->d_namlen == len && !strcmp(dp->d_name, name)) {
closedir(dirp);
return FOUND;
}
closedir(dirp);
return NOT_FOUND;

SEE ALSO
open(2), close(2), read(2), lseek(2), dir(5)