aboutsummaryrefslogtreecommitdiff
path: root/philo_one/common.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-04-22 13:43:00 +0200
committerCharles <sircharlesaze@gmail.com>2020-04-22 13:43:00 +0200
commit3c2c3a07396c001f51eac8d0fd0fc84e83eb127b (patch)
tree7c646f128d97784fba9fd76cf8bb758a9b965c76 /philo_one/common.c
parent2c5abe421b7a1b92081e38f6b1f04d407fcba834 (diff)
downloadphilosophers-3c2c3a07396c001f51eac8d0fd0fc84e83eb127b.tar.gz
philosophers-3c2c3a07396c001f51eac8d0fd0fc84e83eb127b.tar.bz2
philosophers-3c2c3a07396c001f51eac8d0fd0fc84e83eb127b.zip
philo_one refactoring without common lib
Diffstat (limited to 'philo_one/common.c')
-rw-r--r--philo_one/common.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/philo_one/common.c b/philo_one/common.c
new file mode 100644
index 0000000..b9d6e9a
--- /dev/null
+++ b/philo_one/common.c
@@ -0,0 +1,30 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* common.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/08 23:12:55 by cacharle #+# #+# */
+/* Updated: 2020/04/22 13:22:51 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "philo_one.h"
+
+bool parse_args(t_philo_conf *philo_args, int argc, char **argv)
+{
+ if (argc != 5 && argc != 6)
+ return (false);
+ if ((philo_args->philo_num = h_atoi_strict_unsigned(argv[1])) == -1
+ || (philo_args->timeout_death = h_atoi_strict_unsigned(argv[2])) == -1
+ || (philo_args->timeout_eat = h_atoi_strict_unsigned(argv[3])) == -1
+ || (philo_args->timeout_sleep = h_atoi_strict_unsigned(argv[4])) == -1)
+ return (false);
+ if (argc == 6
+ && (philo_args->meal_num = h_atoi_strict_unsigned(argv[5])) == -1)
+ return (false);
+ else
+ philo_args->meal_num = -1;
+ return (true);
+}