Dirent.h

NAME
opendir, readdir, telldir, seekdir, rewinddir, closedir - directory operations

SYNOPSIS
DIR **opendir (dirname)

char **dirname;

struct dirent **readdir (dirp) DIR **dirp;

off_t telldir (dirp) DIR **dirp;

void seekdir (dirp, loc) DIR **dirp; off_t loc;

void rewinddir (dirp) DIR **dirp;

int closedir (dirp) DIR **dirp;


 * 1) i nclude 


 * 1) in clude 

DESCRIPTION
Readdir returns a pointer to an internal structure containing information about the next active directory entry. No inactive entries are reported. The internal structure may be overwritten by another operation on the same directory stream; the amount of storage needed to hold a copy of the internal structure is given by the value of a macro, DIRENTSIZ(strlen(direntp->d_name)), not by sizeof(struct dirent) as one might expect. A NULL pointer is returned upon reaching the end of the directory, upon detecting an invalid location in the directory, or upon occurrence of an error while reading the directory.

Telldir returns the current position associated with the named directory stream for later use as an argument to seekdir.

Seekdir sets the position of the next readdir operation on the named directory stream. The new position reverts to the one associated with the directory stream when the telldir operation from which loc was obtained was performed.

Rewinddir resets the position of the named directory stream to the beginning of the directory. All buffered data for the directory stream is discarded, thereby guaranteeing that the actual file system directory will be referred to for the next readdir on the directory stream.

Closedir closes the named directory stream; internal resources used for the directory stream are liberated, and subsequent use of the associated DIR object is no longer valid. Closedir returns a value of zero if no error occurs, -1 otherwise.

There are several possible errors that can occur as a result of these operations; the external integer variable errno is set to indicate the specific error. (Readdir's detection of the normal end of a directory is not considered to be an error.)

Opendir establishes a connection between the directory named by dirname and a unique object of type DIR known as a directory stream that it creates. Opendir returns a pointer to be used to identify the directory stream in subsequent operations. A NULL pointer is returned if dirname cannot be accessed or is not a directory, or if opendir is unable to create the DIR object (perhaps due to insufficient memory).