/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_printf_atoi.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jguelen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/12/01 13:45:04 by jguelen #+# #+# */ /* Updated: 2024/12/01 17:16:53 by jguelen ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_printf.h" /*Does not deal with the isspace(3) characters. * @RETURN a long castable into an int or LONG_MAX if overflow has * occurred in the positive. */ long ft_printf_atoi(char *str, char **current) { long calc; calc = 0; while (*str && ft_isdigit(*str)) { if ((calc > (INT_MAX / 10)) || ((calc == (INT_MAX / 10)) && ((INT_MAX % 10) < (*str - '0')))) return (LONG_MAX); calc = calc * 10 + (*str - '0'); str++; } *current = str; return (calc); }