mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
34 lines
1.3 KiB
C
34 lines
1.3 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_printf_atoi.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: jguelen <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* 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);
|
|
}
|