manual: Clarify undefined behavior of feenableexcept (BZ 31019)
[glibc.git] / dirent / tst-seekdir.c
blobdcdd699b097563d386bfc8f2f7b61c98e60ec48b
1 #include <stdio.h>
2 #include <dirent.h>
3 #include <stdlib.h>
5 static int
6 do_test (void)
8 DIR * dirp;
9 long int save3 = 0;
10 long int cur;
11 int i = 0;
12 int result = 0;
13 struct dirent *dp;
14 long int save0;
15 long int rewind;
17 dirp = opendir (".");
18 if (dirp == NULL)
20 printf ("opendir failed: %m\n");
21 return 1;
24 save0 = telldir (dirp);
25 if (save0 == -1)
27 printf ("telldir failed: %m\n");
28 result = 1;
31 for (dp = readdir (dirp); dp != NULL; dp = readdir (dirp))
33 /* save position 3 (after fourth entry) */
34 if (i++ == 3)
35 save3 = telldir (dirp);
37 printf ("%s\n", dp->d_name);
39 /* stop at 400 (just to make sure dirp->__offset and dirp->__size are
40 scrambled */
41 if (i == 400)
42 break;
45 printf ("going back past 4-th entry...\n");
47 /* go back to saved entry */
48 seekdir (dirp, save3);
50 /* Check whether telldir equals to save3 now. */
51 cur = telldir (dirp);
52 if (cur != save3)
54 printf ("seekdir (d, %ld); telldir (d) == %ld\n", save3, cur);
55 result = 1;
58 /* print remaining files (3-last) */
59 for (dp = readdir (dirp); dp != NULL; dp = readdir (dirp))
60 printf ("%s\n", dp->d_name);
62 /* Check rewinddir */
63 rewinddir (dirp);
64 rewind = telldir (dirp);
65 if (rewind == -1)
67 printf ("telldir failed: %m\n");
68 result = 1;
70 else if (save0 != rewind)
72 printf ("rewinddir didn't reset directory stream\n");
73 result = 1;
76 closedir (dirp);
77 return result;
80 #define TEST_FUNCTION do_test ()
81 #include "../test-skeleton.c"