Thread-Safe C Library (libc_r.a)
#include <sys/types.h> #include <dirent.h>
int readdir_r (DirectoryPointer, Entry, Result) DIR *DirectoryPointer; struct dirent *Entry; struct dirent **Result;
The readdir_r subroutine returns the directory entry in the structure pointed to by the Result parameter. The readdir_r subroutine returns entries for the . (dot) and .. (dot-dot) directories, if present, but never returns an invalid entry (with d_ino set to 0). When it reaches the end of the directory, or when it detects an invalid seekdir operation, the readdir_r subroutine returns a 9.
Note: The readdir subroutine is reentrant when an application program uses different DirectoryPointer parameter values (returned from the opendir subroutine). Use the readdir_r subroutine when multiple threads use the same directory pointer.
Using the readdir_r subroutine after the closedir subroutine, for the structure pointed to by the DirectoryPointer parameter, has an undefined result. The structure pointed to by the DirectoryPointer parameter becomes invalid for all threads, including the caller.
0 | Indicates that the subroutines was successful. |
9 | Indicates that the subroutines was not successful. |
If the readdir_r subroutine is unsuccessful, the errno global variable is set to one of the following values:
To search a directory for the entry name, enter:
len = strlen(name); DirectoryPointer = opendir("."); for (readdir_r(DirectoryPointer, &Entry, &Result); Result != NULL; readdir_r(DirectoryPointer, &Entry, &Result)) if (dp->d_namlen == len && !strcmp(dp->d_name, name)) { closedir(DirectoryPointer); return FOUND; } closedir(DirectoryPointer); return NOT_FOUND;
These subroutines are part of Base Operating System (BOS) Runtime.
Programs using this subroutine must link to the libpthreads.a library.
The close subroutine, exec subroutines, fork subroutine, lseek subroutine, openx, open, or creat subroutine, read, readv, readx, or readvx subroutine, scandir or alphasort subroutine.
The opendir, readdir, telldir, seekdir, rewinddir, or closedir subroutine.
Subroutines Overview, List of File and Directory Manipulation Services, and List of Multithread Subroutines in AIX Version 4.3 General Programming Concepts: Writing and Debugging Programs.