-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils2.c
59 lines (51 loc) · 1.74 KB
/
utils2.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: crebelo- <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/20 10:51:27 by crebelo- #+# #+# */
/* Updated: 2024/05/02 17:45:41 by crebelo- ### ########.fr */
/* */
/* ************************************************************************** */
#include "philo.h"
int parsing(int argc, char **argv)
{
int i;
i = 1;
if (argc != 5 && argc != 6)
return (error_msg("Error: args: required: 5-6, provided: %d\n", argc));
while (argc)
{
if (!ft_isdigit_str(argv[i]))
return (printf("Error: invalid argument %s\n", argv[i]));
argc--;
i++;
}
if (ft_atoi(argv[1]) <= 0 || ft_atoi(argv[2]) <= 0
|| ft_atoi(argv[3]) <= 0 || ft_atoi(argv[4]) <= 0
|| (argv[5] && ft_atoi(argv[5]) <= 0))
return (printf("Error: invalid argument\n"));
return (0);
}
int clean_memory(t_philosophers *philos)
{
if (philos)
free(philos);
if (controler()->forks)
free(controler()->forks);
return (1);
}
t_data *controler(void)
{
static t_data controler;
return (&controler);
}
unsigned int current_time(void)
{
struct timeval tv;
if (gettimeofday(&tv, NULL))
return (0);
return ((tv.tv_sec * 1000) + (tv.tv_usec / 1000));
}