-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strdup.c
28 lines (25 loc) · 1.18 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: msubtil- <msubtil-@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/25 22:03:13 by msubtil- #+# #+# */
/* Updated: 2022/05/11 21:52:43 by msubtil- ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *src)
{
char *new_str;
size_t str_size;
str_size = ft_strlen(src);
new_str = (char *) malloc(sizeof(char) * (str_size + 1));
if (new_str == NULLPTR)
return (new_str);
while (*src != '\0')
*new_str++ = *src++;
*new_str = '\0';
return (new_str - str_size);
}