-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_utils.c
44 lines (40 loc) · 1.41 KB
/
parse_utils.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* ************************************************************************** */
/* */
/* :::::::: */
/* parse_utils.c :+: :+: */
/* +:+ */
/* By: jvan-hal <[email protected]> +#+ */
/* +#+ */
/* Created: 2023/02/15 13:11:20 by jvan-hal #+# #+# */
/* Updated: 2023/03/02 10:50:12 by jvan-hal ######## odam.nl */
/* */
/* ************************************************************************** */
#include<limits.h>
static int ft_isspace(char c)
{
return (c == '\t' || c == '\n' || c == '\v' || c == '\f' || c == '\r'
|| c == ' ');
}
int atoi_overflow(char *str, double *num)
{
unsigned int res;
res = 0;
*num = 1;
while (ft_isspace(*str))
++str;
if (*str == '+' || *str == '-')
{
if (*str == '-')
*num = -1;
++str;
}
while (*str && *str >= '0' && *str <= '9')
{
res = res * 10 + (*str - '0');
if ((*num == 1 && res > INT_MAX) || (*num == -1 && res - 1 > INT_MAX))
return (0);
++str;
}
*num *= res;
return (1);
}