89 lines
1.4 KiB
C
89 lines
1.4 KiB
C
#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);
|
|
}
|