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, the readdir_r subroutine returns a 0. When it detects an invalid seekdir operation, the readdir_r subroutine returns a 9.
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.
Programs using this subroutine must link to the libpthreads.a library.
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;
The close subroutine, exec subroutines, fork subroutine, lseek subroutine, openx, open, or creat subroutine, read, readv, readx, or readvx (read, readx, readv, readvx, or pread Subroutine) subroutine, scandir or alphasort (scandir or alphasort Subroutine) 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 5L Version 5.2 General Programming Concepts: Writing and Debugging Programs.