-
Notifications
You must be signed in to change notification settings - Fork 0
/
execute_utils_2.c
108 lines (98 loc) · 2.17 KB
/
execute_utils_2.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* execute_utils_2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abuzdin <abuzdin@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/20 09:30:21 by abuzdin #+# #+# */
/* Updated: 2022/08/11 10:05:41 by abuzdin ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void set_std(t_input *data, int in, int out)
{
int ret;
if (in > 0)
{
ret = dup2(data->cmds->in, IN);
error_check(ret, data->cmds->in_arg, data);
}
if (out > 1)
{
ret = dup2(data->cmds->out, OUT);
error_check(ret, data->cmds->out_arg, data);
}
}
void close_fds(int fd1, int fd2, int param)
{
if (param)
{
if (fd1)
close(fd1);
if (fd2 > 1)
close(fd2);
}
if (!param)
{
close(fd1);
close(fd2);
}
}
char *ms_strjoin_free(char *rest, char *buf, t_input *data)
{
char *unis;
size_t i;
size_t j;
if (!rest || !buf)
return (0);
data->j = ft_strlen(rest) + ft_strlen(buf) + 1;
unis = ms_malloc(sizeof(*unis) * data->j, data);
i = 0;
while (rest[i])
{
unis[i] = rest[i];
++i;
}
j = 0;
while (buf[j])
{
unis[i + j] = buf[j];
++j;
}
unis[j + i] = '\0';
free(rest);
return (unis);
}
char *ms_charjoin_free(char *line, char b, t_input *data)
{
size_t i;
char *unis;
i = 0;
while (line[i])
++i;
unis = ms_malloc(sizeof(*unis) * (i + 2), data);
i = 0;
while (line[i])
{
unis[i] = line[i];
++i;
}
unis[i] = b;
unis[i + 1] = 0;
free(line);
return (unis);
}
int is_builtin(t_input *data, t_cmd *cmds)
{
int i;
i = 0;
while (i < 7)
{
if (ft_strcmp(cmds->cmd[0], data->builtins[i].name))
++i;
else
return (1);
}
return (0);
}