#include "../includes/philo_header.h" int check_f(char ch) { if (ch == '\t' || ch == '\n' || ch == ' ' || \ ch == '\v' || ch == '\f' || ch == '\r') return (1); else return (0); } int ft_atoi(const char *str) { int i; unsigned long int result; int operator; i = 0; operator = 1; result = 0; while (check_f(str[i])) i++; if (str[i] == '-' || str[i] == '+') { if (str[i] == '-') operator *= -1; i++; } while (str[i] >= '0' && str[i] <= '9') { if (result > 922337203685477580 && operator == -1) return (0); else if (result > 922337203685477580 && operator == 1) return (-1); result = result * 10 + str[i] - '0'; i++; } return (result * operator); } void *ft_calloc(size_t num, size_t size) { void *addr; unsigned int nbytes; nbytes = num * size; addr = malloc(nbytes); if (!size || !num || (size == 0 && num == 0)) return ((void *)addr); if (!addr) return (NULL); else { memset(addr, '\0', nbytes); } return ((void *)addr); } t_all *structalloc_and_bzero(void) { t_all *all; all = ft_calloc(sizeof(t_all), 1); all->number_of_philosophers = -1; all->time_to_die = -1; all->time_to_eat = -1; all->time_to_sleep = -1; all->number_of_times_each_philosopher_must_eat = -1; return(all); } int return_big(int a, int b) { if (a > b) { return (a); } return (b); } int return_less(int a, int b) { if (a < b) { return (a); } return (b); } time_t ft_get_time(void) { time_t return_value; struct timeval current_time; gettimeofday(¤t_time, NULL); return_value = (current_time.tv_sec * 1000) + (current_time.tv_usec / 1000); return (return_value); } unsigned long ft_time_is(void) { static struct timeval tv; gettimeofday(&tv, NULL); return ((tv.tv_sec * (unsigned long)1000) + (tv.tv_usec / 1000)); }