/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strict_atoi.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/15 10:06:29 by cacharle #+# #+# */ /* Updated: 2020/01/15 14:09:03 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" #include int ft_strict_atoi(const char *s) { char *end; long ret; if (*s != '-' && !ft_isdigit(*s)) { errno = EINVAL; return (0); } errno = 0; ret = ft_strtol(s, &end, 10); if (errno == ERANGE || ret > INT_MAX || ret < INT_MIN) { errno = ERANGE; return (0); } if (*end != '\0') { errno = EINVAL; return (0); } return (ret); }