-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibft_functions_1.c
77 lines (66 loc) · 1.67 KB
/
libft_functions_1.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* libft_functions_1.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfreitas <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/10 15:30:50 by jfreitas #+# #+# */
/* Updated: 2020/02/24 11:00:20 by jfreitas ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
char *ft_strnew(size_t size)
{
char *str;
str = (char*)malloc(sizeof(char) * (size + 1));
if (str == NULL)
return (NULL);
ft_bzero(str, size + 1);
return (str);
}
char *ft_strdup(char const *s1)
{
char *dest;
dest = (char*)malloc(sizeof(char) * ft_strlen(s1) + 1);
if (dest == NULL)
return (NULL);
ft_strcpy(dest, s1);
return (dest);
}
char *ft_strndup(char const *s1, size_t n)
{
char *s2;
size_t i;
i = 0;
if (!(s2 = ft_strnew(n)))
return (NULL);
while (s1[i] && i < n)
{
s2[i] = s1[i];
i++;
}
return (s2);
}
void *ft_memset(void *b, int c, size_t len)
{
char *str;
str = b;
while (len--)
{
*str++ = c;
}
return (b);
}
void ft_bzero(void *s, size_t n)
{
char *str;
size_t i;
str = (char *)s;
i = 0;
while (i < n)
{
str[i] = '\0';
i++;
}
}