aboutsummaryrefslogtreecommitdiff
path: root/common/src/helper.c
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2021-01-10 11:13:54 +0100
committerCharles Cabergs <me@cacharle.xyz>2021-01-10 11:13:54 +0100
commitef97ae4e1659da4ef1a02505730d2ecf2389e608 (patch)
tree23dcb59d3cd90c8169f52f2086ad626aa49514fa /common/src/helper.c
parenteb2cfb574efafcf2c3c6200d1cd2de700ec8ddfb (diff)
downloadphilosophers-ef97ae4e1659da4ef1a02505730d2ecf2389e608.tar.gz
philosophers-ef97ae4e1659da4ef1a02505730d2ecf2389e608.tar.bz2
philosophers-ef97ae4e1659da4ef1a02505730d2ecf2389e608.zip
Refactoring common lib functions to expose only those we need
Diffstat (limited to 'common/src/helper.c')
-rw-r--r--common/src/helper.c58
1 files changed, 5 insertions, 53 deletions
diff --git a/common/src/helper.c b/common/src/helper.c
index 53c24c4..3515cfa 100644
--- a/common/src/helper.c
+++ b/common/src/helper.c
@@ -6,36 +6,12 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/08 23:22:49 by cacharle #+# #+# */
-/* Updated: 2021/01/10 10:32:06 by cacharle ### ########.fr */
+/* Updated: 2021/01/10 11:10:45 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)
@@ -49,6 +25,10 @@ t_time h_time_now(void)
return (tv.tv_sec * 1000 + tv.tv_usec / 1000);
}
+/*
+** usleep is not precise and adds delay if we do one big usleep
+*/
+
void h_sleep(t_time sleep_time)
{
t_time start;
@@ -57,31 +37,3 @@ void h_sleep(t_time sleep_time)
while (h_time_now() - start < sleep_time)
usleep(500);
}
-
-char *h_nbrcpy(char *dst, long long int num)
-{
- if (num > 9)
- dst = h_nbrcpy(dst, num / 10);
- dst[0] = num % 10 + '0';
- return (dst + 1);
-}
-
-char *h_strcpy_end(char *dst, const char *str)
-{
- while (*str != '\0')
- *dst++ = *str++;
- return (dst);
-}
-
-#define PHILO_SEM_EAT_BUF_SIZE 2048
-
-const char *philo_sem_eat_name(const char *prefix, long int id)
-{
- static char buf[PHILO_SEM_EAT_BUF_SIZE];
- char *end;
-
- buf[0] = '\0';
- end = h_strcpy_end(buf, prefix);
- h_nbrcpy(end, id);
- return (buf);
-}