-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_next_line_utils.c
70 lines (62 loc) · 1.73 KB
/
get_next_line_utils.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ael-haib <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/11 17:16:57 by ael-haib #+# #+# */
/* Updated: 2024/07/11 17:17:01 by ael-haib ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
size_t ft_strlen(const char *s)
{
size_t len;
len = 0;
while (s[len] != '\0')
len++;
return (len);
}
char *ft_strchr(const char *s, int c)
{
if (!s)
return (NULL);
c = (unsigned char)c;
while ((*s != '\0') && (*s != c))
s++;
if (*s == c)
return ((char *)s);
return (NULL);
}
void *ft_memcpy(void *dst, const void *src, size_t n)
{
size_t i;
if (!dst && !src)
return (NULL);
i = 0;
while (i < n)
{
*((char *)dst + i) = *((char *)src + i);
i++;
}
return (dst);
}
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *str;
size_t len_s;
if (!s)
return (NULL);
len_s = ft_strlen(s);
if (start > len_s)
len = 0;
if (len_s < len)
len = len_s - start;
str = (char *)malloc((len + 1) * sizeof(char));
if (!str)
return (NULL);
ft_memcpy(str, s + start, len);
str[len] = '\0';
return (str);
}