fstests: drop check.log and check.time into section specific results dir
[xfstests-dev.git] / src / t_readdir_2.c
1 #include <unistd.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include <dirent.h>
6 #include <fcntl.h>
7 #include <sys/stat.h>
8 #include <sys/types.h>
9
10 int main(int argc, char *argv[])
11 {
12         int fd;
13         int ret;
14         DIR *dir;
15         struct dirent *ptr;
16
17         dir = opendir(argv[1]);
18
19         fd = dirfd(dir);
20         if (fd < 0) {
21                 perror("Failed to get dirfd!");
22                 exit(EXIT_FAILURE);
23         }
24         ret = fork();
25
26         if (ret == 0) {
27                 int ret1, i;
28                 static int array[11] = {0, 1, 2, 3, 1023, 1024, 1025, 4095,
29                                         4096, 4097, 0x7fffffff};
30
31                 while(1) {
32                         for(i = 0; i < 11; i++) {
33                                 ret1 = lseek(fd, array[i++], SEEK_SET);
34                                 if (ret1 == -1) {
35                                         perror("Seek failed!");
36                                         exit(EXIT_FAILURE);
37                                 }
38                         }
39
40                         off_t pos = lseek(fd, 0, SEEK_CUR);
41                         lseek(fd, pos, SEEK_SET);
42                 }
43         } else {
44                 while (1) {
45                         int ret2 = lseek(fd, 0, SEEK_SET);
46                         if (ret2 == -1) {
47                                 perror("Seek failed!");
48                                 exit(EXIT_FAILURE);
49                         }
50                         while ((ptr = readdir(dir)))
51                                         ;
52                 }
53         }
54
55         closedir(dir);
56         exit(EXIT_SUCCESS);
57 }