-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strndup.c
31 lines (28 loc) · 1.13 KB
/
ft_strndup.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strndup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ewilliam <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/29 17:26:36 by ewilliam #+# #+# */
/* Updated: 2016/11/29 21:08:53 by ewilliam ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strndup(const char *s1, size_t n)
{
size_t len;
char *s2;
len = ft_strlen(s1);
if (len > n)
len = n;
s2 = malloc(sizeof(char) * len + 1);
if (s2)
{
ft_memcpy(s2, s1, len);
s2[len] = '\0';
return (s2);
}
return (NULL);
}