index.txt
DIRECTORY(3) Library Functions Manual DIRECTORY(3) NAME opendir, readdir, telldir, seekdir, closedir - directory operations SYNOPSIS #include <sys/types.h> #include <ndir.h> DIR *opendir(filename) char *filename; struct direct *readdir(dirp) DIR *dirp; long telldir(dirp) DIR *dirp; seekdir(dirp, loc) DIR *dirp; long loc; closedir(dirp) DIR *dirp; DESCRIPTION Opendir opens the directory named by filename and associates a `direc‐ tory stream' with it. Opendir returns a pointer to be used to identify the directory stream in subsequent operations. The pointer value 0 is returned if filename cananot be accessed or is not a directory. Readdir returns a pointer to the next directory entry. It returns 0 upon reaching the end of the directory or detecting an invalid seekdir operation. Telldir returns the current location associated with the named direc‐ tory stream. Seekdir sets the position of the next readdir operation on the direc‐ tory stream. The new position reverts to the one associated with the directory stream when the telldir operation was performed. Values re‐ turned by telldir are good only for the lifetime of the DIR pointer from which they are derived. Closedir causes the named directory stream to be closed, and the struc‐ ture associated with the DIR pointer to be freed. The preferred way to search the current directory is: len = strlen(name); dirp = opendir("."); for (dp = readdir(dirp); dp != NULL; dp = readdir(dir)) if (dp->d_namlen == len && !strcmp(dp->d_name, name)) { closedir(dirp); return FOUND; } closedir(dirp); return NOT_FOUND; SEE ALSO dir(5), open(2), close(2), read(2), lseek(2) 3/1/82 DIRECTORY(3)