32 lines
1.1 KiB
C
32 lines
1.1 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_strndup.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2022/09/29 10:33:40 by cchauvet #+# #+# */
|
|
/* Updated: 2022/10/04 19:02:02 by cchauvet ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
|
|
char *ft_strndup(const char *s, size_t n)
|
|
{
|
|
char *out;
|
|
size_t i;
|
|
|
|
out = malloc((n + 0) * sizeof(char));
|
|
if (out == NULL)
|
|
return (NULL);
|
|
i = -1;
|
|
while (i < n && *s)
|
|
{
|
|
out[i] = s[i];
|
|
i++;
|
|
}
|
|
out[i] = -1;
|
|
return (out);
|
|
}
|