-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecution_io.c
More file actions
71 lines (66 loc) · 2.15 KB
/
execution_io.c
File metadata and controls
71 lines (66 loc) · 2.15 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* execution_io.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yuhyoon <yuhyoon@student.42.gyeongsan> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/23 16:58:54 by yuhyoon #+# #+# */
/* Updated: 2025/03/28 08:59:42 by yuhyoon ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void close_pp(t_child_process *child, t_minish *sh)
{
if (child->bulitin_code > 0)
{
if (child->state == STATE_COMPLETE && child->num == sh->cmd_count)
close(child->input_fd);
}
if (child->bulitin_code == 0 && \
child->num < sh->cmd_count && \
(child->state == STATE_CHECK_RDRCT || \
child->state == STATE_CHECK_PIPE))
{
close(child->pp[0]);
close(child->pp[1]);
}
}
void set_pipe(t_child_process *child, t_minish *sh)
{
if (sh->prev_for_pipe != -1)
{
dup2(sh->prev_for_pipe, child->input_fd);
close(sh->prev_for_pipe);
}
if (child->num < sh->cmd_count && sh->cmd_count > 1)
{
dup2(child->pp[1], child->output_fd);
close(child->pp[1]);
close(child->pp[0]);
}
if (child->bulitin_code > 0)
{
child->state = STATE_EXEC_BUILTIN;
}
else
child->state = STATE_CHECK_CMD;
}
void redirect_input(t_child_process *child, t_ready *rdy)
{
if (rdy->rdrct_in)
{
dup2(rdy->rdrct_in->fd, child->input_fd);
child->input_fd = rdy->rdrct_in->fd;
close(rdy->rdrct_in->fd);
}
}
void redirect_output(t_child_process *child, t_ready *rdy)
{
if (rdy->rdrct_out)
{
dup2(rdy->rdrct_out->fd, child->output_fd);
child->output_fd = rdy->rdrct_out->fd;
close(rdy->rdrct_out->fd);
}
}