Buy GNU books!
DIR **opendir (dirname)
struct dirent **readdir (dirp)
off_t telldir (dirp)
void seekdir (dirp, loc)
void rewinddir (dirp)
int closedir (dirp)
DIRknown as a directory stream that it creates. Opendir returns a pointer to be used to identify the directory stream in subsequent operations. A
NULLpointer is returned if dirname cannot be accessed or is not a directory, or if opendir is unable to create the
DIRobject (perhaps due to insufficient memory).
returns a pointer to an internal structure
containing information about the next active directory entry.
No inactive entries are reported.
The internal structure may be overwritten by
another operation on the same
the amount of storage needed to hold a copy
of the internal structure is given by the value of a macro,
as one might expect.
pointer is returned
upon reaching the end of the directory,
upon detecting an invalid location in the directory,
or upon occurrence of an error while reading the directory.
Telldir returns the current position associated with the named directory stream for later use as an argument to seekdir.
Seekdir sets the position of the next readdir operation on the named 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.
Rewinddir resets the position of the named directory stream to the beginning of the directory. All buffered data for the directory stream is discarded, thereby guaranteeing that the actual file system directory will be referred to for the next readdir on the directory stream.
closes the named
internal resources used for the
directory stream are liberated,
and subsequent use of the associated
object is no longer valid.
returns a value of zero if no error occurs,
There are several possible errors that can occur as a result of these operations; the external integer variable errno is set to indicate the specific error. (Readdir's detection of the normal end of a directory is not considered to be an error.)
dirp = opendir( "." );
while ( (dp = readdir( dirp )) != NULL )
if ( strcmp( dp->d_name, name ) == 0 )
(void) closedir( dirp );
(void) closedir( dirp );
The value returned by telldir need not have any simple interpretation and should only be used as an argument to seekdir. Similarly, the loc argument to seekdir must be obtained from a previous telldir operation on the same directory stream.
Telldir and seekdir are unreliable when used in conjunction with file systems that perform directory compaction or expansion or when the directory stream has been closed and reopened. It is best to avoid using telldir and seekdir altogether.
The exact set of errno values and meanings may vary among implementations.
Because directory entries can dynamically appear and disappear, and because directory contents are buffered by these routines, an application may need to continually rescan a directory to maintain an accurate picture of its active entries.
|webmaster||delorie software privacy|
|Copyright © 2003 by The Free Software Foundation||Updated Jun 2003|