.\" Copyright (c) 1983 Regents of the University of California.
.\" %sccs.include.redist.man%
.\" @(#)directory.3 6.6 (Berkeley) %G%
opendir, readdir, telldir, seekdir, rewinddir, closedir, dirfd \- directory operations
opendir(const char *filename);
telldir(const DIR *dirp);
seekdir(DIR *dirp, long loc);
opens the directory named by
returns a pointer to be used to identify the
in subsequent operations. The pointer
cannot be accessed, or if it cannot
enough memory to hold the whole thing.
returns a pointer to the next directory entry. It returns
upon reaching the end of the directory or detecting an invalid
returns the current location associated with the named
sets the position of the next
The new position reverts to the one associated with the
operation was performed. Values returned by
are good only for the lifetime of the DIR pointer from which they are derived.
If the directory is closed and then reopened, the
value may be invalidated due to undetected directory compaction.
It is safe to use a previous
value immediately after a call to
resets the position of the named
to the beginning of the directory.
and frees the structure associated with the DIR pointer,
On failure, -1 is returned and errno is set to indicate the error.
returns the integer file descriptor associated with the named
Sample code which searchs a directory for entry ``name'' is:
for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp))
if (dp->d_namlen == len && !strcmp(dp->d_name, name)) {
open(2), close(2), read(2), lseek(2), dir(5)