Skip to content

Commit 07531ab

Browse files
committed
GNL: fixed multi-fd test.
1 parent e672648 commit 07531ab

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

get_next_line_tests/tests/30_bonus_multiple_fd.spec.c

+22-18
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,52 @@
22

33
static void simple_string(t_test *test)
44
{
5-
char *line0;
6-
int p0[2];
5+
char *line_fd0;
6+
int p_fd0[2];
77
int fd0 = 0;
8-
int out0 = dup(fd0);
8+
int out_fd0 = dup(fd0);
99

10-
char *line_fd1;
10+
char *line_fd1;
1111
int p_fd1[2];
1212
int fd1 = 1;
1313
int out_fd1 = dup(fd1);
14-
15-
char *line_fd2;
14+
15+
char *line_fd2;
1616
int p_fd2[2];
1717
int fd2 = 2;
1818
int out_fd2 = dup(fd2);
19-
20-
char *line_fd3;
19+
20+
char *line_fd3;
2121
int p_fd3[2];
2222
int fd3 = 3;
2323
int out_fd3 = dup(fd3);
24-
25-
pipe(p0);
26-
dup2(p0[1], fd0);
24+
25+
pipe(p_fd0);
26+
dup2(p_fd0[1], fd0);
2727
write(fd0, "aaa\nbbb\n", 12);
28-
dup2(out0, fd0);
29-
28+
dup2(out_fd0, fd0);
29+
close(p_fd0[1]);
30+
3031
pipe(p_fd1);
3132
dup2(p_fd1[1], fd1);
3233
write(fd1, "111\n222\n", 12);
3334
dup2(out_fd1, fd1);
34-
35+
close(p_fd1[1]);
36+
3537
pipe(p_fd2);
3638
dup2(p_fd2[1], fd2);
3739
write(fd2, "www\nzzz\n", 12);
3840
dup2(out_fd2, fd2);
41+
close(p_fd2[1]);
3942

4043
pipe(p_fd3);
4144
dup2(p_fd3[1], fd3);
4245
write(fd3, "888\n999\n", 12);
4346
dup2(out_fd3, fd3);
47+
close(p_fd3[1]);
4448

45-
get_next_line(p0[0], &line0);
46-
mt_assert(strcmp(line0, "aaa") == 0);
49+
get_next_line(p_fd0[0], &line_fd0);
50+
mt_assert(strcmp(line_fd0, "aaa") == 0);
4751

4852
get_next_line(p_fd1[0], &line_fd1);
4953
mt_assert(strcmp(line_fd1, "111") == 0);
@@ -54,8 +58,8 @@ static void simple_string(t_test *test)
5458
get_next_line(p_fd3[0], &line_fd3);
5559
mt_assert(strcmp(line_fd3, "888") == 0);
5660

57-
get_next_line(p0[0], &line0);
58-
mt_assert(strcmp(line0, "bbb") == 0);
61+
get_next_line(p_fd0[0], &line_fd0);
62+
mt_assert(strcmp(line_fd0, "bbb") == 0);
5963

6064
get_next_line(p_fd1[0], &line_fd1);
6165
mt_assert(strcmp(line_fd1, "222") == 0);

0 commit comments

Comments
 (0)