-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpipex_libft_other_2.c
More file actions
68 lines (61 loc) · 1.86 KB
/
pipex_libft_other_2.c
File metadata and controls
68 lines (61 loc) · 1.86 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pipex_libft_other_2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: acastrov <acastrov@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/03 22:44:00 by acastrov #+# #+# */
/* Updated: 2025/01/03 23:08:23 by acastrov ### ########.fr */
/* */
/* ************************************************************************** */
#include "pipex.h"
char *ft_strdup(const char *s)
{
char *new_string;
size_t sl;
sl = ft_strlen(s) + 1;
new_string = malloc(sl);
if (new_string == NULL)
return (NULL);
ft_strlcpy(new_string, s, sl);
return (new_string);
}
char *ft_strchr(const char *s, int c)
{
char *c_find_pointer;
c_find_pointer = (char *)s;
while (*c_find_pointer)
{
if (*c_find_pointer == (char)c)
return ((char *)c_find_pointer);
c_find_pointer++;
}
if ((char)c == '\0')
return ((char *)c_find_pointer);
return (NULL);
}
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *sub_string;
size_t sub_string_len;
size_t i;
if (!s)
return (NULL);
sub_string_len = ft_strlen(s);
if (start >= sub_string_len)
return (ft_strdup(""));
if (len > sub_string_len - start)
len = sub_string_len - start;
sub_string = malloc(len + 1);
if (!sub_string)
return (NULL);
i = 0;
while (i < len)
{
sub_string[i] = s[i + start];
i++;
}
sub_string[i] = '\0';
return (sub_string);
}