-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_next_line_utils_bonus.c
103 lines (92 loc) · 2.13 KB
/
get_next_line_utils_bonus.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbiodies <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/20 11:18:27 by rbiodies #+# #+# */
/* Updated: 2021/10/20 14:55:16 by rbiodies ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line_bonus.h"
size_t ft_strlen(char const *s)
{
unsigned long int len;
len = 0;
while (s[len] != '\0')
len++;
return (len);
}
char *ft_strjoin(char const *s1, char const *s2)
{
char *buffer;
unsigned int i;
unsigned int j;
i = 0;
j = 0;
if (s1 == NULL || s2 == NULL)
return (NULL);
buffer = (char *)malloc(sizeof(char) * (ft_strlen(s1) + ft_strlen(s2) + 1));
if (buffer == NULL)
return (NULL);
while (s1[i] != '\0')
{
buffer[i] = s1[i];
i++;
}
while (s2[j] != '\0')
{
buffer[i] = s2[j];
i++;
j++;
}
buffer[i] = '\0';
return (buffer);
}
char *ft_strchr(const char *s, int c)
{
int i;
char ch;
i = 0;
ch = (char)c;
while (s[i] != '\0' && s[i] != ch)
i++;
if (s[i] == ch)
return ((char *)s);
return ((void *)0);
}
char *ft_strdup(const char *s1)
{
int i;
char *buffer;
i = 0;
buffer = (char *)malloc(ft_strlen(s1) + 1);
if (buffer == NULL)
return (0);
while (s1[i] != '\0')
{
buffer[i] = s1[i];
i++;
}
buffer[i] = '\0';
return (buffer);
}
size_t ft_strlcpy(char *dst, const char *src, size_t dstsize)
{
size_t i;
i = 0;
if (dstsize > 0)
{
while (dstsize != 1 && src[i] != '\0')
{
dst[i] = src[i];
i++;
dstsize--;
}
dst[i] = '\0';
}
while (src[i] != '\0')
i++;
return (i);
}