Wed Nov 15 19:22:07 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu>
[glibc.git] / dirent / tst-seekdir.c
blobfc282468fe9b4280420bd70f198c0d9d2404ec46
1 #include <stdio.h>
2 #include <dirent.h>
3 #include <stdlib.h>
5 int
6 main ()
9 DIR * dirp;
10 long save3;
11 int i = 0;
12 struct dirent *dp;
14 dirp = opendir(".");
15 for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp))
17 /* save position 3 (fourth entry) */
18 if (i++ == 3)
19 save3 = telldir(dirp);
21 printf("%s\n", dp->d_name);
23 /* stop at 400 (just to make sure dirp->__offset and dirp->__size are
24 scrambled */
25 if (i == 400)
26 break;
29 /* go back to saved entry */
30 seekdir (dirp, save3);
33 /* print remaining files (3-last) */
34 for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp))
35 printf("%s\n", dp->d_name);
38 closedir (dirp);
39 exit(0);