-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_next_line_utils.c
123 lines (112 loc) · 2.46 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* ************************************************************************** */
/* */
/* :::::::: */
/* get_next_line_utils.c :+: :+: */
/* +:+ */
/* By: kawish <[email protected]> +#+ */
/* +#+ */
/* Created: 2020/12/22 10:40:36 by kawish #+# #+# */
/* Updated: 2021/10/12 12:24:53 by kgajadie ######## odam.nl */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
void *ft_memmove(void *dst, const void *src, size_t len)
{
char *d;
const char *s;
size_t i;
char *d_last;
const char *s_last;
d = dst;
s = src;
if (!dst && !src)
return (0);
if (d < s)
while (len--)
*d++ = *s++;
else
{
i = 0;
d_last = d + (len - 1);
s_last = s + (len - 1);
while (i < len)
{
*(d_last - i) = *(s_last - i);
i++;
}
}
return (dst);
}
size_t ft_strlen(const char *s)
{
size_t len;
len = 0;
while (*s++)
{
len++;
}
return (len);
}
char *c_ft_strdup(const char *s1)
{
size_t s1_len;
char *res;
size_t i;
s1_len = ft_strlen(s1) + 1;
res = malloc(s1_len * sizeof(*res));
if (!res)
return (NULL);
i = 0;
if (!res && !s1)
return (0);
while (i < s1_len)
{
((char *)res)[i] = ((const char *)s1)[i];
i++;
}
return (res);
}
size_t ft_strlcpy(char *dst, const char *src, size_t dstsize)
{
unsigned long srclen;
size_t i;
if (!src || !dst)
return (0);
srclen = ft_strlen(src);
i = 0;
if (dstsize == 0)
return (srclen);
if (srclen == 0)
{
dst[0] = '\0';
return (srclen);
}
while ((src[i] != '\0') && (i < (dstsize - 1)))
{
dst[i] = src[i];
i++;
}
dst[i] = '\0';
return (srclen);
}
size_t ft_strlcat(char *dst, const char *src, size_t dstsize)
{
int i;
size_t dst_len;
size_t dst_len_o;
i = 0;
dst_len = ft_strlen(dst);
dst_len_o = ft_strlen(dst);
if (dstsize > dst_len)
{
while (dst_len < dstsize - 1 && src[i])
{
dst[dst_len] = src[i];
dst_len++;
i++;
}
dst[dst_len] = '\0';
return (dst_len_o + ft_strlen(src));
}
return (dstsize + ft_strlen(src));
}