2023-01-31 08:40:15 -05:00
|
|
|
/* ************************************************************************** */
|
|
|
|
/* */
|
|
|
|
/* ::: :::::::: */
|
|
|
|
/* 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"
|
|
|
|
|
2023-02-14 01:26:18 -05:00
|
|
|
char *ft_strndup(const char *src, size_t n)
|
2023-01-31 08:40:15 -05:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|