-
Notifications
You must be signed in to change notification settings - Fork 1
/
get_next_line_utils.c
82 lines (72 loc) · 1.7 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gkhodizo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/05/03 15:27:44 by gkhodizo #+# #+# */
/* Updated: 2020/06/07 16:53:14 by gkhodizo ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
char *ft_strncpy(char *dst, char *src, size_t len)
{
size_t i;
i = 0;
if (dst == src || len == 0)
return (dst);
while (i < len)
{
dst[i] = src[i];
i++;
}
return (dst);
}
char *ft_strdup(char *s1)
{
size_t i;
size_t len;
char *dup;
if (!s1)
return (NULL);
i = 0;
len = buff_len(s1);
if (!(dup = (char *)malloc((len + 1) * sizeof(char))))
return (NULL);
while (s1[i])
{
dup[i] = s1[i];
i++;
}
dup[i] = '\0';
return (dup);
}
int is_nl(char *s)
{
while (*s)
{
if (*s == '\n')
return (1);
s++;
}
return (0);
}
size_t line_len(char *str)
{
size_t len;
len = 0;
while (str[len] != '\n' && str[len] != '\0')
len++;
return (len);
}
size_t buff_len(char *str)
{
size_t blen;
if (!str)
return (0);
blen = 0;
while (str[blen] != '\0')
blen++;
return (blen);
}