This commit is contained in:
Camille Chauvet
2023-01-31 14:40:15 +01:00
commit 5a102e93a1
90 changed files with 2876 additions and 0 deletions

32
libftx/extra/ft_strndup.c Normal file
View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strndup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/26 00:55:44 by cchauvet #+# #+# */
/* Updated: 2023/01/05 19:27:03 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "extra.h"
char *ft_strndup(char *src, size_t n)
{
char *out;
size_t i;
if (src[0] == '\0')
return (NULL);
out = ft_calloc(n + 1, sizeof(char));
if (out == NULL)
return (NULL);
i = 0;
while (src[i] != '\0' && i < n)
{
out[i] = src[i];
i++;
}
return (out);
}