-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.c
78 lines (70 loc) · 1.93 KB
/
helpers.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* helpers.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mbin-nas <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/02 16:36:18 by mbin-nas #+# #+# */
/* Updated: 2023/01/02 16:36:34 by mbin-nas ### ########.fr */
/* */
/* ************************************************************************** */
#include "pipex.h"
int ft_strncmp(const char *s1, const char *s2, size_t num)
{
size_t i;
unsigned char *ptr1;
unsigned char *ptr2;
ptr1 = (unsigned char *)s1;
ptr2 = (unsigned char *)s2;
i = 0;
if (num == 0 || ptr2 == NULL)
return (0);
while ((i < num - 1) && (ptr1[i] != '\0' && ptr2[i] != '\0')
&& (ptr1[i] == ptr2[i]))
i++;
return (ptr1[i] - ptr2[i]);
}
size_t ft_strlen(const char *c)
{
size_t l;
l = 0;
while (c[l] != '\0')
{
l++;
}
return (l);
}
char *ft_strjoin(char const *str1, char const *str2)
{
char *result;
size_t i;
size_t j;
if (!str1 || !str2)
return (NULL);
result = malloc(sizeof(char) * (ft_strlen(str1) + ft_strlen(str2) + 1));
if (!result)
return (NULL);
i = 0;
j = 0;
while (str1 != NULL && str1[j] != '\0')
result[i++] = str1[j++];
j = 0;
while (str2 != NULL && str2[j] != '\0')
result[i++] = str2[j++];
result[i++] = '\0';
return (result);
}
char *find_path(char **envp)
{
if (envp)
{
while (*envp)
{
if (ft_strncmp("PATH=", *envp, 5) == 0)
return (*envp + 5);
envp++;
}
}
return (0);
}