-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_next_line_utils.c
68 lines (59 loc) · 1.54 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: anhigo-s <anhigo-s@student.42sp.org.br +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/27 22:34:13 by anhigo-s #+# #+# */
/* Updated: 2021/10/10 00:15:44 by anhigo-s ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
char *gnl_strchr(char *str, char c)
{
size_t i;
i = -1;
while (str[++i])
if (str[i] == c)
return (&str[i]);
return (NULL);
}
char *gnl_strdup(char *s)
{
char *new;
char *res;
ssize_t i;
i = 0;
while ((s[i] != '\0'))
i++;
res = malloc(i + 1);
new = res;
while (*s)
*new++ = *s++;
*new = 0;
return (res);
}
size_t gnl_strlen(const char *s)
{
size_t i;
i = 0;
while (s[i] != '\0')
{
i++;
}
return (i);
}
char *gnl_substr(char const *s, unsigned int start, size_t len)
{
char *new;
char *res;
new = malloc(len + 1);
res = new;
while (start--)
s++;
while (len-- && *s)
*new++ = *s++;
*new = 0;
return (res);
}