mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
libs: added libft
This commit is contained in:
parent
6e1552a35d
commit
ddb2306630
63 changed files with 2989 additions and 4 deletions
34
libft/ft_printf_atoi.c
Normal file
34
libft/ft_printf_atoi.c
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue