-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.c
88 lines (84 loc) · 1.94 KB
/
test.c
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* test.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dnakano <dnakano@student.42tokyo.jp> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/19 11:42:12 by dnakano #+# #+# */
/* Updated: 2020/10/20 11:10:28 by dnakano ### ########.fr */
/* */
/* ************************************************************************** */
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include "get_next_line.h"
#ifndef N_FDMAX
#define N_FDMAX 255
#endif
int main(int argc, char **argv)
{
int i;
int j;
int fd[N_FDMAX];
int flag_notfinished;
char *line;
int res;
int flag_stdin;
if (argc == 1)
{
fd[0] = 0;
argc = 2;
flag_stdin = 1;
}
else
{
i = 0;
while (i < argc - 1)
{
fd[i] = open(argv[i + 1], O_RDONLY);
i++;
}
}
flag_notfinished = 1;
i = 0;
while (flag_notfinished)
{
flag_notfinished = 0;
printf("GNL: %d\n", i);
j = 0;
while (j < argc - 1)
{
if (fd[j] != -2)
{
res = get_next_line(fd[j], &line);
printf("fd-%03d: res = %2d", fd[j], res);
if (res == -1)
{
printf(", ERROR!!\n");
fd[j] = -2;
}
else
{
flag_notfinished += res;
printf(", line = \"%s\"\n", line);
free(line);
if (res == 0)
{
if (fd[j] > 2)
close(fd[j]);
fd[j] = -2;
}
}
}
j++;
}
printf("\n");
i++;
}
printf("finished\n");
#ifdef LEAKCHECK
while(1);
#endif
}