Manual Page Result
0
Command: directory | Section: 3 | Source: UNIX v10 | File: directory.3
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 cannot 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.
struct direct {
u_long d_ino; inode for the entry
short d_reclen; don't use
short d_namlen; equivalent to strlen(d_name)
char d_name[MAXNAMLEN+1]; null-terminated entry name
};
The preferred way to search the current directory is:
DIR *dirp;
dirp = opendir(".");
for(dp = readdir(dirp); dp != 0; dp = readdir(dir))
if(strcmp(dp->d_name, name) == 0)
break;
closedir(dirp);
/* found name if dp != 0 */
SEE ALSO
dir(5), open(2), dirread(2), read(2), lseek(2), ftw(3)
BUGS
The return values point to static data whose content is overwritten by
each call.
DIRECTORY(3)