-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuiltin_exit_utils.c
More file actions
executable file
·91 lines (84 loc) · 2.14 KB
/
builtin_exit_utils.c
File metadata and controls
executable file
·91 lines (84 loc) · 2.14 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* builtin_exit_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hyeyeom <hyeyeom@42student.gyeongsan.kr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/28 17:59:09 by hyeyeom #+# #+# */
/* Updated: 2025/04/14 00:38:35 by hyeyeom ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
long long ft_atol(char *str)
{
long long res;
int sign;
res = 0;
sign = 1;
if (*str == '\t' || *str == '\n' || *str == '\v' || *str == '\f'
|| *str == '\r' || *str == ' ')
str++;
if (*str == '+' || *str == '-')
{
if (*str == '-')
sign *= -1;
str++;
}
while ('0' <= *str && *str <= '9')
{
res = res * 10 + *str - '0';
str++;
}
return (sign * res);
}
long long ft_atol_length(char *str)
{
long long res;
int sign;
res = 0;
sign = 1;
if (*str == '\t' || *str == '\n' || *str == '\v' || *str == '\f'
|| *str == '\r' || *str == ' ')
str++;
if (*str == '+' || *str == '-')
{
if (*str == '-')
sign *= -1;
str++;
}
while ('0' <= *str && *str <= '9')
{
if (res > (LLONG_MAX - (*str - '0')) / 10)
return (-1);
res = res * 10 + *str - '0';
str++;
}
return (1);
}
int check_input_length(char *arvs)
{
int flag;
int z_cnt;
int length;
long long res;
flag = 0;
z_cnt = 0;
if (arvs[0] == '-')
{
z_cnt++;
flag = 1;
}
while (arvs[z_cnt] == '0')
z_cnt++;
length = ft_strlen(arvs);
if (length == z_cnt)
return (0);
length = ft_strlen(&arvs[z_cnt]);
if (flag == 1)
length++;
if ((length > 19 && flag == 0) || (length > 20 && flag == 1))
return (-1);
res = ft_atol_length(arvs);
return (res);
}