-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_next_line_utils.c
76 lines (68 loc) · 1.77 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: luciehdr <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/01/08 12:54:59 by hlucie #+# #+# */
/* Updated: 2021/02/04 23:31:04 by luciehdr ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
size_t ft_strlen(char *str)
{
size_t i;
i = 0;
while (str[i] != '\0')
i++;
return (i);
}
void *ft_malloc_ultra(char *ptr, size_t size)
{
char *str;
int i;
int len;
i = -1;
str = NULL;
len = 0;
if (!ptr)
{
if (!(str = malloc(sizeof(char) * (size + 1))))
return (NULL);
*str = '\0';
return (str);
}
len = size + ft_strlen(ptr);
if (!(str = malloc(sizeof(char *) * (ft_strlen(ptr) + len + 1))))
return (NULL);
while (ptr[++i] != '\0')
str[i] = ptr[i];
str[i] = '\0';
ft_free_plz(&ptr);
ptr = NULL;
return (str);
}
char *ft_strdup_custom(char *s, char *str)
{
int i;
char *dest;
i = 0;
dest = NULL;
if (!(dest = malloc(sizeof(char) * (ft_strlen(s) + 1))))
return (NULL);
while (s[i])
{
dest[i] = s[i];
i++;
}
dest[i] = '\0';
ft_free_plz(&str);
return (dest);
}
void ft_free_plz(char **ptr)
{
if (*ptr)
free(*ptr);
*ptr = NULL;
}