Rewinding to the Start of a Directory

To permit a directory to be searched more than once, the open directory must be rewound. This is what the rewinddir(3) function achieves.

#include <sys/types.h>
#include <dirent.h>

void rewinddir(DIR *dirp);

When the directory is initially opened with opendir(3), it is implicitly positioned at the start of the directory. When rewinddir(3) is called, the open directory is repositioned at the start. The input argument dirp is simply the pointer to the open DIR structure that was returned by opendir(3). There is no return value for rewinddir(3), and there are no documented errors for this call.

The following shows how the function can be called:

DIR *dirp;             /* Open DIR pointer */

rewinddir(dirp);
					

Get Advanced UNIX Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.