-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils_1.c
79 lines (68 loc) · 1.66 KB
/
utils_1.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils_1.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: phelebra <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/19 12:46:54 by fvonsovs #+# #+# */
/* Updated: 2023/08/11 13:42:46 by phelebra ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
extern int g_status;
int you_fucked_up(char *msg, int status)
{
g_status = status;
printf("\tERROR status %i: %s\n", status, msg);
exit(1);
}
void free_array(char **ptr)
{
size_t i;
i = 0;
while (ptr[i] != NULL)
{
free(ptr[i]);
i++;
}
free(ptr);
}
char *ft_strcat(char *dest, char *src)
{
int i;
int l;
i = 0;
l = ft_strlen(dest);
while (src[i] != '\0')
{
dest[i + l] = src[i];
i++;
}
dest[i + l] = '\0';
return (dest);
}
char *ft_strcpy(char *s1, char *s2)
{
int i;
i = 0;
while (s2[i])
{
s1[i] = s2[i];
i++;
}
s1[i] = s2[i];
return (s1);
}
int ft_strcmp(char *s1, char *s2)
{
int i;
if (s1 == NULL || s2 == NULL)
{
return (-1);
}
i = 0;
while (s1[i] == s2[i] && s1[i] != '\0' && s2[i] != '\0')
i++;
return (s1[i] - s2[i]);
}