-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_liba.c
77 lines (69 loc) · 1.77 KB
/
utils_liba.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
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils_liba.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: alvutina <alvutina@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/12 10:15:33 by alvutina #+# #+# */
/* Updated: 2024/06/12 10:27:20 by alvutina ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void ft_putstr_fd(char *s, int fd)
{
if (!s)
return ;
while (*s)
{
write(fd, s, 1);
s++;
}
}
int ft_min(int a, int b)
{
if (a <= b)
return (a);
return (b);
}
int ft_max(int a, int b)
{
if (a >= b)
return (a);
return (b);
}
int args_len(char **split_args)
{
int i;
i = 0;
while (split_args[i])
i++;
return (i);
}
long int ft_atoi(const char *str)
{
long int final_result;
int i;
int sign;
if (!str)
return (0);
i = 0;
while ((str[i] >= 9 && str[i] <= 13) || str[i] == 32)
i++;
sign = 1;
if (str[i] == '-' || str[i] == '+')
{
if (str[i] == '-')
sign = -1;
i++;
}
final_result = 0;
while (str[i] != '\0' && (str[i] >= '0' && str[i] <= '9'))
{
final_result = final_result * 10 + (str[i] - 48);
i++;
}
if (final_result * sign > 2147483647 || final_result * sign < -2147483648)
return (2147483650);
return (final_result * sign);
}