Fri Jul 5 12:22:51 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
[glibc.git] / dirent / tst-seekdir.c
blob3022783e54e9d3718c257ff668f3b781874317b3
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 (after 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 printf("going back past 4-th entry...\n");
31 /* go back to saved entry */
32 seekdir (dirp, save3);
35 /* print remaining files (3-last) */
36 for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp))
37 printf("%s\n", dp->d_name);
40 closedir (dirp);
41 exit(0);