-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_next_line_utils_bonus.c
More file actions
81 lines (73 loc) · 1.93 KB
/
Copy pathget_next_line_utils_bonus.c
File metadata and controls
81 lines (73 loc) · 1.93 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tsargsya <tsargsya@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/26 19:22:28 by tsargsya #+# #+# */
/* Updated: 2025/01/11 20:01:51 by tsargsya ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line_bonus.h"
#include <stdlib.h>
char *ft_strchr(const char *s, int c)
{
while (*s)
{
if (*s == (char)c)
return ((char *)s);
s++;
}
if ((char)c == 0)
return ((char *)s);
return (NULL);
}
char *strjoin_till_nl(char *line, char *buffer)
{
char *str;
size_t size;
size_t i;
size_t j;
i = 0;
if (!line || !buffer)
return (NULL);
j = ft_strlen(line);
while (buffer[i] && buffer[i] != '\n')
i++;
if (buffer[i] == '\n')
i++;
size = i + j;
str = malloc((size + 1) * sizeof(char));
if (!str)
return (free(line), NULL);
ft_memcpy(str, line, j);
i = 0;
while (buffer[i] && buffer[i] != '\n')
str[j++] = buffer[i++];
if (buffer[i] == '\n')
str[j++] = buffer[i++];
str[j] = '\0';
return (free(line), str);
}
size_t ft_strlen(char *str)
{
size_t i;
i = 0;
while (str[i])
i++;
return (i);
}
void *ft_memcpy(void *dest, const void *src, size_t n)
{
size_t i;
if (dest == NULL && src == NULL)
return (dest);
i = 0;
while (i < n)
{
((unsigned char *)dest)[i] = ((unsigned char *)src)[i];
i++;
}
return (dest);
}