generic: new case to test getcwd(2)
[xfstests-dev.git] / src / t_readdir_1.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                 char buf[100];
28
29                 while(1)
30                         read(fd, buf, 100);
31
32         } else {
33                 while (1) {
34                         int ret2 = lseek(fd, 0, SEEK_SET);
35                         if (ret2 == -1) {
36                                 perror("Seek failed!");
37                                 exit(EXIT_FAILURE);
38                         }
39                         while ((ptr = readdir(dir)))
40                                         ;
41                 }
42         }
43
44         closedir(dir);
45         exit(EXIT_SUCCESS);
46 }