-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strdup.c
37 lines (34 loc) · 1.21 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
28
29
30
31
32
33
34
35
36
37
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbin-jef <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/28 15:19:31 by sbin-jef #+# #+# */
/* Updated: 2024/08/12 00:37:15 by sbin-jef ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <unistd.h>
#include <stddef.h>
#include <stdlib.h>
char *ft_strdup(const char *str)
{
size_t len;
size_t i;
char *dup;
len = 0;
while (str[len] != '\0')
len++;
dup = malloc ((len +1) * sizeof (char));
if (!dup)
return (NULL);
i = 0;
while (i <= len)
{
dup[i] = str[i];
i++;
}
return (dup);
}