-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_next_line_utils_bonus.c
95 lines (85 loc) · 2.08 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
/* ************************************************************************** */
/* */
/* :::::::: */
/* get_next_line_utils.c :+: :+: */
/* +:+ */
/* By: rcappend <[email protected]> +#+ */
/* +#+ */
/* Created: 2020/11/30 10:36:53 by rcappend #+# #+# */
/* Updated: 2020/11/30 10:41:33 by rcappend ######## odam.nl */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
/*
** Strlen adjusted to stop counting after finding a specific character.
*/
size_t ft_strclen(const char *str, int c)
{
size_t i;
if (!*str)
return (0);
i = 0;
while (str[i] != '\0')
{
i++;
if (str[i] == (unsigned char)c && c != 0)
return (i);
}
return (i);
}
/*
** Memccpy adjusted to copy until it finds the character.
** If it finds the character, it null terminates destination.
** It also returns destination instead of NULL.
*/
char *ft_memccpy(char *dst, const char *src, int c)
{
if (!src)
return (dst);
while (*src)
{
if (*src == (unsigned char)c && c != 0)
{
*dst = '\0';
return ((char *)src);
}
*dst = *src;
dst++;
src++;
}
*dst = '\0';
return (dst);
}
/*
** Moves memory from end of buffer to beginning,
** Then makes the rest of the buffer 0.
*/
void ft_memmove(char *dst, const char *src)
{
size_t src_len;
size_t i;
if (*src == '\n')
src++;
src_len = ft_strclen(src, 0);
i = 0;
while (i < BUFFER_SIZE)
{
if (i <= src_len)
dst[i] = src[i];
else
dst[i] = 0;
i++;
}
}
char *ft_strchr(const char *s, int c)
{
while (TRUE)
{
if (*s == (char)c)
return ((char *)s);
if (*s == '\0')
break ;
s++;
}
return (NULL);
}