-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvariable_parser_2.c
More file actions
65 lines (59 loc) · 1.63 KB
/
Copy pathvariable_parser_2.c
File metadata and controls
65 lines (59 loc) · 1.63 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* variable_parser_2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aboncine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/09 12:25:35 by aboncine #+# #+# */
/* Updated: 2023/02/09 12:30:19 by aboncine ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
char *ft_extact_var_free(char *dopo, char *tmp2, char *res, char *s)
{
if (dopo[0] != '\0')
{
tmp2 = ft_strjoin(res, dopo);
free (s);
free(res);
free(dopo);
return (tmp2);
}
free(s);
free(dopo);
return (res);
}
char *ft_ft_extract_var_getenv(char *res, int *flag)
{
char *tmp;
tmp = getenv(res);
if (!tmp)
{
tmp = malloc(1);
tmp[0] = '\0';
*flag = 1;
}
return (tmp);
}
int ft_atoi(const char *nptr)
{
int i;
int segno;
int nbr;
i = 0;
segno = 1;
nbr = 0;
while ((nptr[i] >= 9 && nptr[i] <= 13) || nptr[i] == 32)
i++;
if (nptr[i] == '-')
segno = -1;
if (nptr[i] == '-' || nptr[i] == '+')
i++;
while (nptr[i] >= '0' && nptr[i] <= '9')
{
nbr = nbr * 10 + nptr[i] - 48;
i++;
}
return (nbr * segno);
}