Skip to content

Commit

Permalink
gamp
Browse files Browse the repository at this point in the history
  • Loading branch information
mirsella committed Sep 18, 2023
1 parent b7efb40 commit 53a1552
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
2 changes: 2 additions & 0 deletions include/malloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "unistd.h"
#include <errno.h>
#include <stdbool.h>
#include <syslog.h>

#define MMAP_SHIFT(mmap) ((void *)mmap + sizeof(t_mmap))
#define ALLOC_SHIFT(alloc) ((void *)alloc + sizeof(t_alloc))
Expand Down Expand Up @@ -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);
28 changes: 26 additions & 2 deletions src/global_init.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
#include "../include/malloc.h"
#include <bits/pthreadtypes.h>
#include <pthread.h>

t_mmap *g_mmap = NULL;

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);
}

0 comments on commit 53a1552

Please sign in to comment.