-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.c
84 lines (76 loc) · 1.87 KB
/
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
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: alvutina <alvutina@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/29 11:43:43 by alvutina #+# #+# */
/* Updated: 2024/07/29 11:43:43 by alvutina ### ########.fr */
/* */
/* ************************************************************************** */
#include "philo.h"
static int ft_isdigit(int ascii_nbr)
{
if (ascii_nbr >= '0' && ascii_nbr <= '9')
return (1);
return (0);
}
int check_digit(char **str)
{
int i;
int j;
i = 1;
while (str[i])
{
j = 0;
while (str[i][j])
{
if (!ft_isdigit(str[i][j]))
return (1);
j++;
}
i++;
}
return (0);
}
int ft_atoi(const char *str)
{
int i;
long res;
i = 0;
res = 0;
while ((str[i] >= 9 && str[i] <= 13) || (str[i] == ' '))
i++;
if (str[i] == '-')
return (1);
else if (str[i] == '+')
i++;
while (str[i] >= '0' && str[i] <= '9')
{
res = (res * 10) + (str[i] - '0');
i++;
}
if (res > INT_MAX)
return (1);
return (res);
}
void *ft_calloc(size_t count, size_t size)
{
size_t i;
size_t j;
char *ptr;
i = 0;
j = count * size;
if (size >= SIZE_MAX / count)
return (NULL);
ptr = malloc(count * size);
if (!ptr)
return (NULL);
while (i < j)
{
ptr[i] = '\0';
i++;
}
return (ptr);
}