-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strndup.c
29 lines (26 loc) · 1.15 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strndup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tairribe <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/09 22:45:16 by ebezerra #+# #+# */
/* Updated: 2023/08/19 15:13:36 by tairribe ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strndup(const char *str, size_t n)
{
size_t len;
char *copy;
len = 0;
while (len < n && str[len])
len++;
copy = ft_calloc(len + 1, sizeof (char));
if (copy == NULL)
return (NULL);
ft_memcpy(copy, str, len);
copy[len] = '\0';
return (copy);
}