Push_swap/libft/ft_atoll.c

39 lines
1.3 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoll.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/03 17:25:06 by lfirmin #+# #+# */
/* Updated: 2024/11/03 17:25:33 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
long long ft_atoll(const char *str)
{
long long result;
int sign;
result = 0;
sign = 1;
while (*str == ' ' || (*str >= 9 && *str <= 13))
str++;
if (*str == '-' || *str == '+')
{
if (*str == '-')
sign = -1;
str++;
}
while (*str >= '0' && *str <= '9')
{
if (result > INT_MAX || result < INT_MIN)
return (2147483648);
result = result * 10 + (*str - '0');
str++;
}
return (result * sign);
}