From 53a1552001008287521f3f5be195094e5da973ce Mon Sep 17 00:00:00 2001 From: mirsella Date: Mon, 18 Sep 2023 17:24:28 +0200 Subject: [PATCH] gamp --- include/malloc.h | 2 ++ src/global_init.c | 28 ++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/include/malloc.h b/include/malloc.h index d99e5cc..da48a57 100644 --- a/include/malloc.h +++ b/include/malloc.h @@ -8,6 +8,7 @@ #include "unistd.h" #include #include +#include #define MMAP_SHIFT(mmap) ((void *)mmap + sizeof(t_mmap)) #define ALLOC_SHIFT(alloc) ((void *)alloc + sizeof(t_alloc)) @@ -77,3 +78,4 @@ void show_alloc_mem(); void show_alloc_mem_asciidump(); void show_alloc_mem_hexdump(); char *get_type_string(t_type type); +void log(int priority, char *title, size_t size); diff --git a/src/global_init.c b/src/global_init.c index a3e34fa..064474b 100644 --- a/src/global_init.c +++ b/src/global_init.c @@ -1,6 +1,4 @@ #include "../include/malloc.h" -#include -#include t_mmap *g_mmap = NULL; @@ -8,3 +6,29 @@ pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER; void lock_mutex() { pthread_mutex_lock(&g_mutex); } void unlock_mutex() { pthread_mutex_unlock(&g_mutex); } + +void ft_strcat_nbr(char *dest, size_t nbr) { + int i; + + i = 0; + if (nbr < 0) { + dest[ft_strlen(dest)] = '-'; + nbr = -nbr; + } + if (nbr > 9) { + ft_strcat_nbr(dest, nbr / 10); + ft_strcat_nbr(dest, nbr % 10); + } else { + dest[ft_strlen(dest)] = nbr + '0'; + } +} + +// TODO: test this +void log(int priority, char *title, size_t size) { + if (ft_strlen(title) + ft_nbrlen(size) >= 500) + return; + char buffer[512]; + ft_bzero(&buffer, 128); + ft_strlcpy(buffer, title, ft_strlen(title) + 1); + ft_strcat_nbr(buffer, size); +}