aboutsummaryrefslogtreecommitdiff
path: root/philo_one/helper.c
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2021-01-03 14:42:46 +0100
committerCharles Cabergs <me@cacharle.xyz>2021-01-03 14:47:11 +0100
commitcc2adbf09541c0d9309d66f719c86e7fe5d351d7 (patch)
treef9d61b11e57dcdfebc9092554df1a64d0d4958c5 /philo_one/helper.c
parente874ad94a31a8259b8eb7ad2865767c081bcd279 (diff)
downloadphilosophers-rendu.tar.gz
philosophers-rendu.tar.bz2
philosophers-rendu.zip
Updated philo directories for correctionrendu
Diffstat (limited to 'philo_one/helper.c')
-rw-r--r--philo_one/helper.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/philo_one/helper.c b/philo_one/helper.c
new file mode 100644
index 0000000..e1cc1e2
--- /dev/null
+++ b/philo_one/helper.c
@@ -0,0 +1,50 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* helper.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/08 23:22:49 by cacharle #+# #+# */
+/* Updated: 2021/01/02 12:07:49 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "common.h"
+
+long int h_atou_strict(char *s)
+{
+ long int num;
+ char *origin;
+
+ origin = s;
+ if (*s < '0' || *s > '9')
+ return (h_err(-1, "Error: %s: is not a number", origin));
+ num = 0;
+ while (*s >= '0' && *s <= '9')
+ {
+ num *= 10;
+ if (num > UINT_MAX)
+ return (h_err(-1, "Error: %s: is too big", origin));
+ num += *s - '0';
+ if (num > UINT_MAX)
+ return (h_err(-1, "Error: %s: is too big", origin));
+ s++;
+ }
+ if (*s != '\0')
+ return (h_err(-1, "Error: %s: is not a number", origin));
+ return (num);
+}
+
+/*
+** No need to check error of gettimeofday
+** (only for settimeofday and passed pointer validity)
+*/
+
+t_time h_time_now(void)
+{
+ struct timeval tv;
+
+ gettimeofday(&tv, NULL);
+ return (tv.tv_sec * 1000 + tv.tv_usec / 1000);
+}