-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strdup.c
38 lines (34 loc) · 1.41 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
38
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_strdup.c :+: :+: */
/* +:+ */
/* By: kgajadie <[email protected]> +#+ */
/* +#+ */
/* Created: 2020/11/17 17:11:21 by kgajadie #+# #+# */
/* Updated: 2020/11/24 13:59:58 by kgajadie ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
** DESCRIPTION
** The strdup() function allocates
** sufficient memory for a copy of the string s1, does the
** copy, and returns a pointer to it.
** The pointer may subsequently be used as an argument
** to the function free(3).
**
** If insufficient memory is available,
** NULL is returned and errno is set to ENOMEM.
*/
char *ft_strdup(const char *s1)
{
size_t s1_len;
char *res;
s1_len = ft_strlen(s1) + 1;
res = malloc(s1_len * sizeof(*res));
if (!res)
return (NULL);
ft_memcpy(res, s1, s1_len);
return (res);
}