gtpc2m5x | C/C++ Language Support User's Guide |
This function repositions an open directory stream to the beginning of the stream.
Format
#include <dirent.h> void rewinddir(DIR *dir);
The next call to the readdir function reads the first entry in the directory. If the contents of the directory have changed since the directory was opened, a call to the rewinddir function updates the directory stream so that a subsequent readdir function can read the new contents.
Normal Return
There is no returned value.
Error Return
Not applicable.
Programming Considerations
None.
Examples
The following example produces the contents of a directory by opening it, rewinding it, and closing it.
#include <dirent.h> #include <errno.h> #include <sys/types.h> #include <stdio.h> main() { DIR *dir; struct dirent *entry; if ((dir = opendir("/")) == NULL) perror("opendir() error"); else { puts("contents of root:"); while ((entry = readdir(dir)) != NULL) printf("%s ", entry->d_name); rewinddir(dir); puts(""); while ((entry = readdir(dir)) != NULL) printf("%s ", entry->d_name); closedir(dir); puts(""); } }
Output
contents of root: . .. dev usr . .. dev usr
Related Information
See Appendix E, Programming Support for the TPF File System for more information about TPF File System C Functions.