/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_substr.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/09/28 16:33:43 by erey-bet #+# #+# */ /* Updated: 2022/10/11 22:09:26 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" char *ft_substr(char const *s, unsigned int start, size_t len) { long size; char *new_s; if (s == NULL) return (NULL); size = ft_strlen(s) - start; if (size < 0) size = 0; else if ((unsigned long)size > len) size = len; new_s = malloc(size + 1); if (new_s == NULL) return (NULL); if (start <= ft_strlen(s)) ft_strlcpy(new_s, s + start, len + 1); else new_s[0] = '\0'; return (new_s); }