Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ rewinddir(3) — A/UX 3.0.1

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

close(2)

getdirentries(2)

lseek(2)

open(2)

read(2)

dir(4)

ls(1)




directory(3) directory(3)
NAME opendir, readdir, telldir, seekdir, rewinddir, closedir - perform operations on directories SYNOPSIS #include <sys/types.h> #include <dirent.h> br #include <sys/dir.h> DIR *opendir(filename) char *filename; struct direct *readdir(dirp) DIR *dirp; long telldir(dirp) DIR *dir seekdir(dirp, loc) DIR *dirp long loc; void rewinddir(dirp) DIR *dirp; void closedir(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 allocate enough memory to hold the entire file. 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. telldir returns the current location associated with the named directory stream. seekdir sets the position of the next readdir operation on the directory stream. The new position reverts to the one associated with the directory stream when the telldir operation was performed. Values returned by telldir are good only for the lifetime of the DIR pointer from which they are derived. If the directory is closed and then reopened, the telldir value can be invalidated because of undetected directory compaction. It is safe to use a previous telldir value immediately after a call to opendir and before any calls to readdir. January 1992 1



directory(3) directory(3)
rewinddir resets the position of the named directory stream to the beginning of the directory. It also causes the directory stream to refer to the current state of the directory. closedir closes the named directory stream and frees the structure associated with the DIR pointer. EXAMPLES The following sample code searches a directory for an entry name: len = strlen(name); dirp = opendir("."); for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) if (dp->d_namlen == len && !strcmp(dp->d_name, name)) { closedir(dirp); return FOUND; } closedir(dirp); return NOT_FOUND; The result of using a directory stream after executing exec(2) is undefined. After executing a fork(2), either the parent or the child (but not both) can continue processing the directory stream by using readdir or rewinddir, or both. SEE ALSO close(2), getdirentries(2), lseek(2), open(2), read(2), dir(4) ls(1) in A/UX Command Reference 2 January 1992

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026