-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_next_line_utils.c
99 lines (88 loc) · 2.25 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fvieira <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/14 12:02:53 by fvieira #+# #+# */
/* Updated: 2022/11/14 12:02:55 by fvieira ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
#include <stdio.h>
size_t ft_strlen(const char *str)
{
size_t count;
count = 0;
while (str[count] != '\0')
count++;
return (count);
}
void ft_bzero(void *s, size_t n)
{
char *str2;
str2 = s;
while (n > 0)
{
str2[n - 1] = '\0';
n--;
}
}
void *ft_calloc(size_t nitems, size_t size)
{
void *array;
array = malloc(nitems * size);
if (!array)
return (NULL);
ft_bzero(array, nitems * size);
return (array);
}
char *ft_alt_strjoin(char *s1, char *s2)
{
size_t len_s1;
size_t len_s2;
size_t count;
char *joined;
count = 0;
if (!s1)
s1 = ft_calloc(1, sizeof(char));
len_s1 = ft_strlen(s1);
len_s2 = ft_strlen(s2);
joined = ft_calloc((len_s1 + len_s2 + 1), sizeof(char));
while (s1[count] != '\0')
{
joined[count] = s1[count];
count++;
}
count = 0;
while (s2[count] != '\0')
{
joined[len_s1 + count] = s2[count];
count++;
}
joined[len_s1 + count] = '\0';
free(s1);
return (joined);
}
char *ft_alt_strdup(char *s2, const char *string, size_t size)
{
size_t len_string;
size_t count;
char *array;
free(s2);
len_string = ft_strlen(string);
if (len_string > size)
len_string = size;
count = 0;
array = (char *) malloc((len_string + 1) * sizeof(char));
if (!array)
return (NULL);
while (string[count] != '\0' && count < size - 1)
{
array[count] = string[count];
count++;
}
array[count] = '\0';
return (array);
}