-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.c
54 lines (47 loc) · 1.53 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wlalaoui <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/18 10:41:36 by wlalaoui #+# #+# */
/* Updated: 2024/01/03 13:21:06 by wlalaoui ### ########.fr */
/* */
/* ************************************************************************** */
#include "philo.h"
int ft_atoi(const char *str)
{
int number;
int signe;
number = 0;
signe = 1;
while (*str == ' ' || (*str >= 9 && *str <= 13))
str++;
if (*str == '-' || *str == '+')
{
if (*str == '-')
signe *= -1;
str++;
}
while (*str >= '0' && *str <= '9')
{
number = number * 10 + (*str - 48);
str++;
}
return (number * signe);
}
int ft_usleep(size_t time_in_ms)
{
size_t begin_time;
begin_time = cur_t();
while ((cur_t() - begin_time) < time_in_ms)
usleep(500);
return (0);
}
size_t cur_t(void)
{
struct timeval current_time;
gettimeofday(¤t_time, NULL);
return ((current_time.tv_sec * 1000) + (current_time.tv_usec / 1000));
}