Update.
[glibc.git] / dirent / tst-seekdir.c
blobf4d99ae6326f7a64a64545f07344aea6b6b05851
1 #include <stdio.h>
2 #include <dirent.h>
3 #include <stdlib.h>
5 int
6 main (int argc, char *argv[])
9 DIR * dirp;
10 long int save3 = 0;
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 return 0;