aboutsummaryrefslogtreecommitdiff
path: root/common/io.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 /common/io.c
parente874ad94a31a8259b8eb7ad2865767c081bcd279 (diff)
downloadphilosophers-rendu.tar.gz
philosophers-rendu.tar.bz2
philosophers-rendu.zip
Updated philo directories for correctionrendu
Diffstat (limited to 'common/io.c')
-rw-r--r--common/io.c82
1 files changed, 0 insertions, 82 deletions
diff --git a/common/io.c b/common/io.c
deleted file mode 100644
index 5d50ccc..0000000
--- a/common/io.c
+++ /dev/null
@@ -1,82 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* io.c :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2020/09/30 10:03:53 by cacharle #+# #+# */
-/* Updated: 2021/01/03 14:02:21 by cacharle ### ########.fr */
-/* */
-/* ************************************************************************** */
-
-#include "common.h"
-
-static size_t st_strlen(char *s)
-{
- int counter;
-
- counter = 0;
- while (s[counter])
- counter++;
- return (counter);
-}
-
-static char *st_nbrcpy(char *dst, long long int num)
-{
- if (num > 9)
- dst = st_nbrcpy(dst, num / 10);
- dst[0] = num % 10 + '0';
- dst[1] = '\0';
- return (dst + 1);
-}
-
-static void st_strcat(char *dst, char *str)
-{
- while (*dst != '\0')
- dst++;
- while (*str != '\0')
- *dst++ = *str++;
- *dst = '\0';
-}
-
-void philo_put(size_t id, t_philo_event event, t_time initial_time)
-{
- static char buf[2048];
-
- buf[0] = '\0';
- st_nbrcpy(buf, h_time_now() - initial_time);
- st_strcat(buf, " ");
- st_nbrcpy(buf + st_strlen(buf), id);
- if (event == EVENT_FORK)
- st_strcat(buf, " has taken fork\n");
- else if (event == EVENT_EAT)
- st_strcat(buf, " is eating\n");
- else if (event == EVENT_SLEEP)
- st_strcat(buf, " is sleeping\n");
- else if (event == EVENT_THINK)
- st_strcat(buf, " is thinking\n");
- else if (event == EVENT_DIE)
- st_strcat(buf, " died\n");
- write(STDOUT_FILENO, buf, st_strlen(buf));
-}
-
-int h_err(int ret, const char *format, char *str)
-{
- while (*format != '\0')
- {
- if (format[0] == '%' && format[1] == 's')
- {
- if (str != NULL)
- write(STDERR_FILENO, str, st_strlen(str));
- format += 2;
- }
- else
- {
- write(STDERR_FILENO, format, 1);
- format++;
- }
- }
- write(STDERR_FILENO, "\n", 1);
- return (ret);
-}