directory(3) CLIX directory(3)
NAME
directory: opendir, readdir, telldir, seekdir, rewinddir, closedir -
Provide directory operations
LIBRARY
Standard C Library (libc.a)
SYNOPSIS
#include <sys/types.h>
#include <dirent.h>
DIR *opendir(
char *dirname );
struct dirent *readdir(
DIR *dirp );
long telldir(
DIR *dirp );
void seekdir(
DIR *dirp ,
long loc );
void rewinddir(
DIR *dirp );
void closedir(
DIR *dirp );
PARAMETERS
dirname Specifies the name of a directory.
dirp Points to a directory stream.
loc Specifies an address.
DESCRIPTION
The opendir() function opens the directory named by dirname and associates
a directory stream with it. The opendir() function returns a pointer to
be used to identify the directory stream in subsequent operations. The
pointer NULL is returned if dirname cannot be accessed or is not a
directory, or if it cannot malloc() enough memory to hold a DIR structure
or a buffer for the directory entries.
2/94 - Intergraph Corporation 1
directory(3) CLIX directory(3)
The readdir() function returns a pointer to the next active directory
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.
The telldir() function returns the current location associated with the
named directory stream.
The seekdir() function 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 from which loc was
obtained was performed. Values returned by telldir() are good only if the
directory has not changed due to compaction or expansion. This is not a
problem with System V, but it may be with some file system types.
The rewinddir() function resets the position of the named directory stream
to the beginning of the directory.
The closedir() closes the named directory stream and frees the DIR
structure.
EXAMPLES
To search a directory for entry name:
dirp = opendir(".");
while ((dp = readdir(dirp)) != NULL)
if (strcmp(dp->d_name, name) == 0) {
closedir(dirp);
return FOUND;
}
closedir(dirp);
return NOT_FOUND;
CAUTIONS
The rewinddir() function is implemented as a macro, so its function
address cannot be taken.
RETURN VALUES
The opendir() function returns a pointer to a directory stream or NULL.
The readdir() function returns a pointer to the next active directory
entry or NULL. The telldir() function returns the address of the
specified directory stream. The seekdir(), rewinddir() and closedir()
functions do not return values.
ERRORS
The following errors can occur as a result of a call to opendir():
2 Intergraph Corporation - 2/94
directory(3) CLIX directory(3)
[ENOTDIR] A component of dirname is not a directory.
[EACCES] A component of dirname denies search permission.
[EMFILE] The maximum number of file descriptors are currently open.
[EFAULT] The specified dirname points outside the allocated address
space.
The following errors can occur as a result of a call to readdir():
[ENOENT] The current file pointer for the directory is not located at a
valid entry.
[EBADF] The file descriptor determined by the DIR stream is no longer
valid. This results if the DIR stream has been closed.
The following error can occur as a result of a cal to telldir(),
seekdir(), or closedir():
[EBADF] The file descriptor determined by the DIR stream is no longer
valid. This results if the DIR stream has been closed.
RELATED INFORMATION
Functions: getdents(2)
Files: dirent(0)
2/94 - Intergraph Corporation 3