33 lines
1.2 KiB
C
33 lines
1.2 KiB
C
|
/* ************************************************************************** */
|
||
|
/* */
|
||
|
/* ::: :::::::: */
|
||
|
/* 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);
|
||
|
}
|