diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2020-09-29 14:56:27 +0200 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2020-09-29 14:56:27 +0200 |
| commit | 6bfcd3c6f921e7717e61167b291bb27bd3f66386 (patch) | |
| tree | 67b2aa4b8a036cb355f90b1f94438b7eb46441f1 /philo_one/src/args.c | |
| parent | ac4278405b7a258010219499cccc0dd978201caf (diff) | |
| download | philosophers-6bfcd3c6f921e7717e61167b291bb27bd3f66386.tar.gz philosophers-6bfcd3c6f921e7717e61167b291bb27bd3f66386.tar.bz2 philosophers-6bfcd3c6f921e7717e61167b291bb27bd3f66386.zip | |
Fixing taking none existing fork in logs
Diffstat (limited to 'philo_one/src/args.c')
| -rw-r--r-- | philo_one/src/args.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/philo_one/src/args.c b/philo_one/src/args.c new file mode 100644 index 0000000..b7277dd --- /dev/null +++ b/philo_one/src/args.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* args.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/08 23:12:55 by cacharle #+# #+# */ +/* Updated: 2020/09/29 11:08:06 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "philo_one.h" + +bool parse_args(t_philo_conf *philo_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 ((philo_args->philo_num = h_atou_strict(argv[1])) == -1 + || (philo_args->timeout_death = h_atou_strict(argv[2])) == -1 + || (philo_args->timeout_eat = h_atou_strict(argv[3])) == -1 + || (philo_args->timeout_sleep = h_atou_strict(argv[4])) == -1) + return (false); + if (argc == 6) + { + if ((philo_args->meal_num = h_atou_strict(argv[5])) == -1) + return (false); + } + else + philo_args->meal_num = 1; + return (true); +} |
