-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strndup.c
24 lines (21 loc) · 1.1 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strndup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hnoh <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/01/07 11:34:02 by hnoh #+# #+# */
/* Updated: 2021/01/07 11:35:41 by hnoh ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strndup(const char *s1, size_t n)
{
const size_t len = ft_strnlen(s1, n);
char *dst;
if (!(dst = malloc((len + 1) * sizeof(char))))
return (NULL);
ft_strlcpy(dst, s1, len + 1);
return (dst);
}