blob: 7799a0c42a22a93b4e65615cc37fb135c81a1bd6 (
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* helper.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/08 23:22:49 by cacharle #+# #+# */
/* Updated: 2020/02/15 00:53:47 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "common.h"
long int h_strtoposint(char *s)
{
long int num;
if (*s < '0' || *s > '9')
return (-1);
num = 0;
while (*s >= '0' && *s <= '9')
{
num *= 10;
num += *s - '0';
s++;
}
if (*s != '\0')
return (-1);
return num;
}
int h_strlen(char *s)
{
int counter;
counter = 0;
while (s[counter])
counter++;
return (counter);
}
void h_putnbr(unsigned long int num)
{
if (num > 9)
h_putnbr(num / 10);
h_putchar(num % 10 + '0');
}
void h_putchar(char c)
{
write(STDOUT_FILENO, &c, 1);
}
void h_putstr(char *s)
{
write(STDOUT_FILENO, s, h_strlen(s));
}
void *h_calloc(int count, int size)
{
int i;
void *ptr;
if ((ptr = malloc(count * size)) == NULL)
return (NULL);
i = count * size;
while (i-- > 0)
((unsigned char*)ptr)[i] = 0x0;
return (ptr);
}
t_time h_timeval_to_time(struct timeval *tp)
{
t_time t;
t = tp->tv_sec * 1000 + tp->tv_usec / 1000;
return (t);
}
t_time h_time_now(void)
{
struct timeval tv;
if (gettimeofday(&tv, NULL) == -1)
return (-1);
return (h_timeval_to_time(&tv));
}
|