* sysdeps/posix/sysconf.c (__sysconf_check_spec): Only define
[glibc.git] / dirent / tst-seekdir.c
blobb833c30705fc06864956c2c75c7355dc0afbf3f4
1 #include <stdio.h>
2 #include <dirent.h>
3 #include <stdlib.h>
5 int
6 main (int argc, char *argv[])
8 DIR * dirp;
9 long int save3 = 0;
10 long int cur;
11 int i = 0;
12 int result = 0;
13 struct dirent *dp;
15 dirp = opendir (".");
16 for (dp = readdir (dirp); dp != NULL; dp = readdir (dirp))
18 /* save position 3 (after fourth entry) */
19 if (i++ == 3)
20 save3 = telldir (dirp);
22 printf ("%s\n", dp->d_name);
24 /* stop at 400 (just to make sure dirp->__offset and dirp->__size are
25 scrambled */
26 if (i == 400)
27 break;
30 printf ("going back past 4-th entry...\n");
32 /* go back to saved entry */
33 seekdir (dirp, save3);
35 /* Check whether telldir equals to save3 now. */
36 cur = telldir (dirp);
37 if (cur != save3)
39 printf ("seekdir (d, %ld); telldir (d) == %ld\n", save3, cur);
40 result = 1;
43 /* print remaining files (3-last) */
44 for (dp = readdir (dirp); dp != NULL; dp = readdir (dirp))
45 printf ("%s\n", dp->d_name);
48 closedir (dirp);
49 return result;