readdir(3C) (BSD Compatibility Package) readdir(3C)
NAME
readdir - directory operation
SYNOPSIS
/usr/ucb/cc [flag ...] file ... -lucb
#include <sys/types.h>
#include <sys/dir.h>
struct direct *readdir(DIR *dirp);
DESCRIPTION
readdir returns a pointer to the next active directory entry and posi-
tions the directory stream at the next entry. No inactive entries are
returned. It returns NULL upon reaching the end of the directory or
upon detecting an invalid location in the directory. readdir buffers
several directory entries per actual read operation; readdir marks for
update the statime field of the directory each time the directory is
actually read.
DIAGNOSTICS
readdir returns NULL on failure and sets errno to the following value:
ENOENT The current file pointer for the directory is not located at
a valid entry. Stream has been closed.
EXAMPLE
Here is a sample program that prints the names of all the files in the
current directory:
#include <sys/types.h>
#include <sys/dir.h>
main()
{
DIR *p;
struct direct *de;
int status = 0;
if ((p =opendir (".")) == NULL ) {
perror("opendir");
exit(1);
}
while (de = readdir(p)) {
printf("%s\n", de->dname);
}
exit(status);
}
SEE ALSO
directory(3C), direct(4).
Page 1 Reliant UNIX 5.44 Printed 11/98