blob: ba5756d7ab452e620987093f3f8945731fb0dd13 (
plain)
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
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/17 11:57:11 by dkaiser #+# #+# */
/* Updated: 2025/01/21 12:04:22 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_utils.h"
int ft_err(const char *str)
{
printf("\e[31m[ERROR] %s\e[0m\n", str);
return (EXIT_FAILURE);
}
int ft_cur_time_in_ms(void)
{
int time_in_ms;
struct timeval t;
gettimeofday(&t, NULL);
time_in_ms = (t.tv_sec * 1000) + (t.tv_usec / 1000);
return (time_in_ms);
}
void ft_log(int id, const char *str)
{
printf("%u %d %s\n", ft_cur_time_in_ms(), id, str);
}
int ft_atoi(const char *str)
{
int result;
int i;
int posneg;
posneg = 1;
result = 0;
i = 0;
while ((str[i] >= '\t' && str[i] <= '\r') || str[i] == ' ')
{
i++;
}
if (str[i] == '-')
{
posneg = -1;
i++;
}
else if (str[i] == '+')
i++;
while (str[i] >= '0' && str[i] <= '9')
{
result = 10 * result + str[i] - '0';
i++;
}
return (result * posneg);
}
|