-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_next_line_utils_bonus.c
90 lines (81 loc) · 1.94 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: davgalle <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/07 21:34:19 by davgalle #+# #+# */
/* Updated: 2023/10/30 14:04:08 by davgalle ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line_bonus.h"
size_t ft_strlen(char *str)
{
int i;
i = 0;
if (!str)
return (0);
while (str[i] != '\0')
i++;
return (i);
}
char *ft_strchr(char *s, int c)
{
int i;
if (!s)
return (NULL);
i = 0;
while (s[i] != '\0')
{
if (s[i] == (unsigned char)c)
return ((char *)&s[i] + 1);
i++;
}
if ((char)c == '\0')
return ((char *)&s[i]);
return (NULL);
}
char *ft_strjoin(char *board, char *buffer)
{
size_t i;
size_t z;
char *board_dir;
if (ft_strlen(buffer) == 0)
return (board);
board_dir = malloc((ft_strlen(board) + ft_strlen(buffer) + 1));
if (!board_dir)
{
free(board);
return (NULL);
}
i = -1;
while (board[++i] != '\0')
board_dir[i] = board[i];
z = 0;
while (buffer[z] != '\0')
board_dir[i++] = buffer[z++];
board_dir[i] = '\0';
free(board);
return (board_dir);
}
char *ft_strdup(char *s1)
{
int i;
int len;
char *s2;
if (!s1)
return (NULL);
i = 0;
len = ft_strlen(s1);
s2 = malloc(len + 1);
if (!s2)
return (NULL);
while (s1[i] != '\0')
{
s2[i] = s1[i];
i++;
}
s2[i] = '\0';
return (s2);
}