This is the mail archive of the cygwin mailing list for the Cygwin project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
| Other format: | [Raw text] | |
After a rewinddir, readdir seems to return as many empty entries as there
were actual entries left to read, followed by . and ..
$ cat rewdir.c
#include <stdio.h>
#include <dirent.h>
#include <errno.h>
#include <string.h>
void readentries(DIR *dh, int limit) {
struct dirent *de;
int count;
for (count = 0; count < limit; ++count) {
errno = 0;
if ((de = readdir(dh)) == NULL) {
if (errno != 0) printf ("read error: %s\n", strerror (errno));
break;
}
printf ("got: %s\n", de->d_name);
}
}
int main(int argc, char **argv)
{
DIR *dh;
if (argc != 2) return 1;
if ( (dh = opendir (argv[1])) == NULL ) {
fprintf (stderr, "couldn't open '%s': %s\n", argv[1], strerror (errno));
return 1;
}
readentries (dh, 4);
printf ("rewinding.\n");
errno = 0;
rewinddir (dh);
if (errno != 0) printf ("unexpected errno: %d\n", errno);
readentries (dh, 9999);
return 0;
}
$ rm -rf foo; mkdir foo; touch foo/{bar,baz,quux,quuux,quuuux}
$ ./rewdir foo
got: .
got: ..
got: bar
got: baz
rewinding.
got:
got:
got:
got: .
got: ..
Attachment:
cygcheck.out
Description: Text document
-- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |