-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.c
More file actions
101 lines (91 loc) · 2.18 KB
/
utils.c
File metadata and controls
101 lines (91 loc) · 2.18 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
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adurusoy <adurusoy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/20 22:14:45 by adurusoy #+# #+# */
/* Updated: 2023/12/27 21:07:55 by adurusoy ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
#include <sys/wait.h>
#include <stdlib.h>
#include <unistd.h>
void handle_relative_path(char **pwd, t_parse *current_parse)
{
char *str;
char *temp;
t_parse *m_next;
str = getcwd(NULL, 0);
m_next = current_parse->next;
*pwd = ft_strjoin(str, "/");
free(str);
temp = ft_strjoin(*pwd, m_next->text[0]);
free(*pwd);
*pwd = temp;
}
void wait_all(t_shell *m_shell)
{
t_parse *data;
data = m_shell->parse;
while (data)
{
if (!data->next)
waitpid(data->pid, &m_shell->exec_status, 0);
else
waitpid(data->pid, 0, 0);
data = data->next;
}
m_shell->exec_status = WEXITSTATUS(m_shell->exec_status);
}
void clear_pipe(int *fd)
{
int index;
if (fd)
{
index = -1;
while (++index < 2)
{
if (fd[index])
close(fd[index]);
}
}
}
void ft_newlstiter(t_list *lst, void (*f)(void *, t_shell *), t_shell *shell)
{
if (!lst || !f)
return ;
while (lst != NULL)
{
f(lst->content, shell);
lst = lst->next;
}
}
char *ft_mini_strdup2(size_t len, char *s, int i, const char *str)
{
int j;
j = 0;
while (i < (int)len)
{
if (str[i] == '\"')
{
i++;
while (str[i] != '\"')
s[j++] = str[i++];
i++;
}
else if (str[i] == '\'')
{
i++;
while (str[i] != '\'')
s[j++] = str[i++];
i++;
}
else
s[j++] = str[i++];
}
s[j] = '\0';
return (s);
}