-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathms_utils.c
More file actions
84 lines (74 loc) · 1.87 KB
/
ms_utils.c
File metadata and controls
84 lines (74 loc) · 1.87 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ms_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jinsecho <jinsecho@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/01 20:17:30 by jinsecho #+# #+# */
/* Updated: 2024/12/22 20:38:51 by jinsecho ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void ft_line_split_free(char **tmp)
{
int i;
i = 0;
while (tmp[i])
free(tmp[i++]);
free(tmp);
}
char *ft_envchr(char *env, char *str)
{
int i;
i = 0;
while (env[i] != '=' && env[i])
{
if (env[i] != str[i])
return (NULL);
i++;
}
if (env[i] == '=' && str[i] == 0)
return (env);
else
return (NULL);
}
char *ft_realloc(char *ptr, int size)
{
char *tmp;
tmp = (char *)malloc(sizeof(char) * size + 1);
if (tmp == NULL)
exit (EXIT_FAILURE);
ft_strlcpy(tmp, ptr, ft_strlen(ptr) + 1);
free(ptr);
return (tmp);
}
long long ft_atoll(const char *str)
{
int minus;
int i;
long long c;
minus = 1;
i = 0;
c = 0;
while ((9 <= str[i] && str[i] <= 13) || str[i] == 32)
i++;
if (str[i] == '-' || str[i] == '+')
{
if (str[i] == '-')
minus *= -1;
i++;
}
while ('0' <= str[i] && str[i] <= '9')
{
c *= 10;
c = c + (str[i] - '0');
i++;
}
return ((minus * c) % 256);
}
void count_ca_cnt(t_plst *l)
{
while (l->pipe_split[l->ca_cnt])
l->ca_cnt++;
}