-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strdup.c
27 lines (24 loc) · 1.15 KB
/
ft_strdup.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: chanheki <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/06 18:47:31 by chanheki #+# #+# */
/* Updated: 2022/07/25 20:26:07 by chanheki ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *s1)
{
size_t str_length;
char *dest;
str_length = ft_strlen(s1);
dest = (char *) malloc(sizeof(char) * str_length + 1);
if (!dest)
return (NULL);
*(dest + str_length) = 0;
ft_memcpy(dest, s1, str_length);
return (dest);
}