forked from josanri/Libft_extended
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strdup.c
35 lines (32 loc) · 1.29 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aalvarez <aalvarez@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/08/17 01:37:30 by aalvarez #+# #+# */
/* Updated: 2022/08/17 20:10:21 by aalvarez ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
/**
* @brief allocates a copy of the string pointed by s1 and returns it.
*
* @param s1 the string to be copied.
* @return char* the allocated copy.
*/
char *ft_strdup(const char *s1)
{
char *result;
int i;
result = malloc(sizeof(char) * (ft_strlen(s1) + 1));
if (!result)
return (NULL);
i = -1;
while (s1[++i])
result[i] = s1[i];
result[i] = 0;
return (result);
}