2023-02-24 06:46:02 -05:00
|
|
|
/* ************************************************************************** */
|
|
|
|
/* */
|
|
|
|
/* ::: :::::::: */
|
|
|
|
/* ft_atoi_check.c :+: :+: :+: */
|
|
|
|
/* +:+ +:+ +:+ */
|
|
|
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
|
|
|
/* +#+#+#+#+#+ +#+ */
|
|
|
|
/* Created: 2022/07/21 08:21:05 by erey-bet #+# #+# */
|
2023-02-28 08:36:07 -05:00
|
|
|
/* Updated: 2023/02/28 13:52:13 by erey-bet ### ########.fr */
|
2023-02-24 06:46:02 -05:00
|
|
|
/* */
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
static int ft_isspace(char c)
|
|
|
|
{
|
|
|
|
if (c == ' ' || c == '\f'
|
|
|
|
||c == '\n' || c == '\r' || c == '\t' || c == '\v')
|
|
|
|
return (1);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ft_atoi_check(const char *nptr)
|
|
|
|
{
|
|
|
|
long result;
|
|
|
|
int sign;
|
|
|
|
|
|
|
|
while (ft_isspace(*nptr))
|
|
|
|
nptr++;
|
|
|
|
sign = 1;
|
|
|
|
if (*nptr == '+' || *nptr == '-')
|
|
|
|
{
|
|
|
|
if (*nptr == '-')
|
|
|
|
sign = -1;
|
|
|
|
nptr++;
|
|
|
|
}
|
|
|
|
result = 0;
|
|
|
|
while (*nptr >= '0' && *nptr <= '9')
|
|
|
|
{
|
|
|
|
result = result * 10 + *nptr++ - '0';
|
|
|
|
if ((result > 2147483647 && sign == 1)
|
2023-02-28 08:36:07 -05:00
|
|
|
|| (result > 2147483647 && sign == 1))
|
|
|
|
return (2);
|
2023-02-24 06:46:02 -05:00
|
|
|
}
|
|
|
|
if (*nptr--)
|
2023-02-28 08:36:07 -05:00
|
|
|
return (1);
|
2023-02-24 06:46:02 -05:00
|
|
|
if (*nptr == '-' || *nptr == '+')
|
2023-02-28 08:36:07 -05:00
|
|
|
return (1);
|
|
|
|
return (0);
|
2023-02-24 06:46:02 -05:00
|
|
|
}
|