summaryrefslogtreecommitdiff
path: root/src/t_readdir_1.c
blob: 37b37f045229c068fdd291ab94e14beb533acf8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>

int main(int argc, char *argv[])
{
	int fd;
	int ret;
	DIR *dir;
	struct dirent *ptr;

	dir = opendir(argv[1]);

	fd = dirfd(dir);
	if (fd < 0) {
		perror("Failed to get dirfd!");
		exit(EXIT_FAILURE);
	}
	ret = fork();

	if (ret == 0) {
		char buf[100];

		while(1)
                        read(fd, buf, 100);

	} else {
		while (1) {
			int ret2 = lseek(fd, 0, SEEK_SET);
			if (ret2 == -1) {
				perror("Seek failed!");
				exit(EXIT_FAILURE);
			}
			while ((ptr = readdir(dir)))
					;
		}
	}

	closedir(dir);
	exit(EXIT_SUCCESS);
}