update from main archive 970214
[glibc/history.git] / dirent / tst-seekdir.c
blob5a5c7fdd36e1cfa50d85b5080789d48476950cdc
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 exit(0);