48 lines
1.5 KiB
C
48 lines
1.5 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* utils.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2022/02/25 03:28:46 by apommier #+# #+# */
|
|
/* Updated: 2022/02/25 03:28:46 by apommier ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "philosophers.h"
|
|
|
|
long ft_atoi(const char *nptr)
|
|
{
|
|
int i;
|
|
long nbr;
|
|
long minus;
|
|
|
|
minus = 1;
|
|
nbr = 0;
|
|
i = 0;
|
|
while ((nptr[i] >= 9 && nptr[i] <= 13) || nptr[i] == 32)
|
|
i++;
|
|
if (nptr[i] == '+')
|
|
i++;
|
|
else if (nptr[i] == '-')
|
|
{
|
|
i++;
|
|
minus = -1;
|
|
}
|
|
while (nptr[i] >= '0' && nptr[i] <= '9')
|
|
{
|
|
nbr = nbr * 10 + nptr[i] - '0';
|
|
i++;
|
|
}
|
|
return (minus * nbr);
|
|
}
|
|
|
|
long get_time(void)
|
|
{
|
|
struct timeval time;
|
|
|
|
gettimeofday(&time, NULL);
|
|
//printf("time : %ld\n", time.tv_sec * 1000 + time.tv_usec / 1000);
|
|
return (time.tv_sec * 1000 + time.tv_usec / 1000);
|
|
} |