-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strdup.c
27 lines (24 loc) · 1.09 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: yrigny <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/10 17:05:20 by yrigny #+# #+# */
/* Updated: 2023/11/10 17:05:23 by yrigny ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *s)
{
size_t len;
char *dup;
len = 0;
while (s[len])
len++;
dup = (char *)malloc(sizeof(char) *(len + 1));
if (!dup)
return (0);
return (ft_memcpy(dup, s, len + 1));
}