-
Notifications
You must be signed in to change notification settings - Fork 0
/
time.c
54 lines (47 loc) · 1.43 KB
/
time.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* time.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: smia <smia@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/26 09:32:42 by smia #+# #+# */
/* Updated: 2022/03/15 05:36:46 by smia ### ########.fr */
/* */
/* ************************************************************************** */
#include "philo.h"
long long get_time(void)
{
struct timeval x;
gettimeofday(&x, NULL);
return ((x.tv_sec * 1e3) + (x.tv_usec / 1e3));
}
void ft_usleep(unsigned long time)
{
unsigned long curr;
curr = get_time();
while (get_time() - curr < time)
usleep(50);
}
int ft_atoi(char *str)
{
int i;
int n;
i = 0;
n = 0;
while ((str[i] >= 9 && str[i] <= 13) || str[i] == ' ')
i++;
while (str[i])
{
if (str[i] >= '0' && str[i] <= '9')
{
n = n * 10 + str[i] - 48;
i++;
}
else
return (-1);
}
if (n > 2147483647)
return (-1);
return (n);
}