13#include "utils/utils.h"
18int main(
int argc,
char **argv)
22 if (argc != 5 && argc != 6)
23 return (
err(
"n_philos time_to_die time_to_eat"
24 " time_to_sleep [eat_count]\n", 1));
25 if (
atoi_errable(argv[1], &opt.n) || opt.n < 1 || opt.n > 1000)
26 return (
err(
"Number of philosophers must be between 1 and 1000\n", 1));
27 if (
atoi_errable(argv[2], &opt.tt_die) || opt.tt_die < 1)
28 return (
err(
"Time to die must be between 1 "
29 "and 2147483647\n", 1));
30 if (
atoi_errable(argv[3], &opt.tt_eat) || opt.tt_eat < 1)
31 return (
err(
"Time to eat must be between 1 "
32 "and 2147483647\n", 1));
33 if (
atoi_errable(argv[4], &opt.tt_sleep) || opt.tt_sleep < 1)
34 return (
err(
"Time to sleep must be between 1 "
35 "and 2147483647\n", 1));
37 if (argc == 6 && (
atoi_errable(argv[5], &opt.eat_n) || opt.eat_n < 1))
38 return (
err(
"Eat count must be between 1 and 2147483647\n", 1));
int atoi_errable(const char *str, int *n)
Converts ascii digits from str to a signed integer, output into n . Returns 0 on success,...
int err(const char *str, int retval)
Write str to stderr and return retval.
int seat(t_opt opt)
Allocate for, initialize, seat, wait on (pun intended), and free all philos.