-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathft_strdup.c
More file actions
39 lines (35 loc) · 1.41 KB
/
Copy pathft_strdup.c
File metadata and controls
39 lines (35 loc) · 1.41 KB
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
38
39
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cado-car <cado-car@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/07/30 20:24:40 by cado-car #+# #+# */
/* Updated: 2021/07/31 11:25:45 by cado-car ### ########lyon.fr */
/* */
/* ************************************************************************** */
/*
* LIBRARY
* #include <string.h>
* DESCRIPTION
* The strdup() function allocates sufficient memory for a copy of the string
* s1, does the copy, and returns a pointer to it.
* PARAMETERS
* #1. The string to duplicate.
* RETURN VALUES
* The strdup() function returns thE pointer to the copy of s1.
*/
#include "libft.h"
char *ft_strdup(const char *s1)
{
int size;
char *ptr;
size = ft_strlen((char *)s1);
ptr = malloc((size + 1) * sizeof(char));
if (ptr == NULL)
return (NULL);
ft_memcpy(ptr, s1, size);
ptr[size] = '\0';
return (ptr);
}