From 99f67bde096ad84dad5b41bc779ae2ad2d807e6f Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Wed, 30 Sep 2020 10:35:23 +0200 Subject: Renaming io_* -> event_*, Changed philo_put with only 1 write call --- common/args.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 common/args.c (limited to 'common/args.c') diff --git a/common/args.c b/common/args.c new file mode 100644 index 0000000..6392f22 --- /dev/null +++ b/common/args.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* args.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/08 23:12:55 by cacharle #+# #+# */ +/* Updated: 2020/09/30 10:14:24 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "common.h" + +bool parse_args(t_philo_args *args, int argc, char **argv) +{ + if (argc != 5 && argc != 6) + return h_err(false, "Usage: %s philosophers_num death_timeout eat_timeout sleep_timeout [meal_num]", argv[0]); + if ((args->philo_num = h_atou_strict(argv[1])) == -1 + || (args->timeout_death = h_atou_strict(argv[2])) == -1 + || (args->timeout_eat = h_atou_strict(argv[3])) == -1 + || (args->timeout_sleep = h_atou_strict(argv[4])) == -1) + return (false); + if (argc == 6) + { + if ((args->meal_num = h_atou_strict(argv[5])) == -1) + return (false); + } + else + args->meal_num = 1; + return (true); +} -- cgit