-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_next_line_utils.c
executable file
·94 lines (84 loc) · 1.3 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
#include "get_next_line.h"
size_t ft_strlen(char *s)
{
size_t len;
len = 0;
if (s == NULL)
return (0);
while (s[len] != '\0')
{
len++;
}
return (len);
}
size_t ft_strlen_n(char *s)
{
size_t len;
len = 0;
if (s == NULL)
return (0);
while (s[len] != '\n')
{
len++;
}
return (len);
}
size_t ft_strlcat(char *dst, char *src, size_t dstsize)
{
unsigned int i;
unsigned int j;
unsigned int dlen;
unsigned int slen;
i = 0;
if (dst == NULL || src == NULL)
return (0);
dlen = ft_strlen(dst);
slen = ft_strlen(src);
j = dlen;
if (dstsize == 0 || dstsize <= dlen)
return (slen + dstsize);
while (src[i] != '\0' && i < dstsize - dlen - 1)
{
dst[j] = src[i];
i++;
j++;
}
dst[j] = '\0';
return (dlen + slen);
}
char *ft_strjoin(char *s1, char *s2)
{
char *str;
size_t len;
if (s1 == NULL)
s1 = "";
if (s2 == NULL)
s2 = "";
len = ft_strlen(s1) + ft_strlen(s2);
str = malloc(sizeof(char) * (len + 1));
if (str == NULL)
return (NULL);
ft_strlcpy(str, s1, len + 1);
ft_strlcat(str, s2, len + 1);
return (str);
}
char *ft_strchr(char *s, int c)
{
unsigned int i;
i = 0;
if (s == NULL)
return (NULL);
while (s[i] != '\0')
{
if (s[i] == (unsigned char)c)
{
return ((char *)&s[i]);
}
i++;
}
if ((char)c == s[i])
{
return ((char *)&s[i]);
}
return (NULL);
}