-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_utils15.c
60 lines (53 loc) · 975 Bytes
/
ft_utils15.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
#include "minishell.h"
char *search_env(t_list *l, char *str)
{
t_elem *c;
int tmp;
int mal;
char *res;
c = l->first;
tmp = ft_strlen(str) + 1;
mal = 0;
while (c->next != NULL)
{
if (ft_strncmp(str, c->data, ft_strlen(str)) == 0
&& ft_strncmp(str, c->data, ft_strlen_egal(c->data)) == 0)
{
while (c->data[tmp])
{
mal++;
tmp++;
}
res = search_env_2(c, str, tmp, mal);
return (res);
}
c = c->next;
}
return (NULL);
}
char *search_env_2(t_elem *courant, char *str, int tmp, int mal)
{
char *res;
res = malloc(sizeof (char) * (mal + 1));
if (res == NULL)
return (NULL);
tmp = ft_strlen(str) + 1;
mal = 0;
while (courant->data[tmp])
res[mal++] = courant->data[tmp++];
res[mal] = '\0';
return (res);
}
int ft_putchar_int(int c)
{
unsigned char s;
s = (unsigned char) c;
write(1, &c, 1);
return (s);
}
void check_q3(t_struct *d, int i, char *str)
{
str = check_q2(d, i, str);
if (d->l.line)
free_str(str);
}