-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_next_line_utils.c
102 lines (91 loc) · 2.05 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yel-bouk <yel-bouk@student.42nice.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/13 20:19:54 by yel-bouk #+# #+# */
/* Updated: 2024/11/19 16:27:20 by yel-bouk ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
//Locates the first occurrence of a character in a string.
char *ft_strchr(const char *str, int c)
{
int i;
i = 0;
while (str[i])
{
if (str[i] == (char)c)
return ((char *)&str[i]);
i++;
}
if ((char)c == '\0')
return ((char *)&str[i]);
return (NULL);
}
size_t ft_strlcpy(char *dest, const char *src, size_t size)
{
size_t i;
size_t len;
len = ft_strlen(src);
i = 0;
if (size == 0)
return (len);
while (src[i] && i < size - 1)
{
dest[i] = src[i];
i++;
}
dest[i] = '\0';
return (len);
}
void *ft_memmove(void *dest, const void *src, size_t n)
{
size_t i;
unsigned char *s;
unsigned char *d;
if (dest == src || n == 0)
return (dest);
i = 0;
s = (unsigned char *)src;
d = (unsigned char *)dest;
if (d < s)
{
while (i < n)
{
d[i] = s[i];
i++;
}
}
else if (s < d)
{
while (n-- > 0)
{
d[n] = s[n];
}
}
return (dest);
}
size_t ft_strlen(const char *str)
{
int i;
i = 0;
while (str[i])
{
i++;
}
return (i);
}
char *ft_strdup(const char *str)
{
char *cpy;
int len;
len = ft_strlen(str) + 1;
cpy = malloc((len) * sizeof(char));
if (!cpy)
return (NULL);
ft_strlcpy(cpy, str, len);
return (cpy);
}