From fb83ac114fa877c0ea3f861ab69c06d8632cbdcd Mon Sep 17 00:00:00 2001 From: tomoron Date: Fri, 21 Mar 2025 13:14:26 +0100 Subject: [PATCH] finish README.md and tests and fix makefile relink for tests rule --- Makefile | 5 ++--- README.md | 6 ++++++ tests.c | 7 ++++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 1c00869..dff0036 100755 --- a/Makefile +++ b/Makefile @@ -42,9 +42,8 @@ LFT_DIR = libft/ all: libft_malloc.so -exec: $(OBJS_DIR) $(NAME) $(LFT) -# $(CC) -o a.out $(FLAGS) main.c $(NAME) $(LFT) - $(CC) -o a.out $(FLAGS) tests.c -L. -lft_malloc $(LFT) -Wl,-rpath=. +tests: $(OBJS_DIR) $(NAME) $(LFT) tests.c + $(CC) -o tests $(FLAGS) tests.c -L. -lft_malloc $(LFT) -Wl,-rpath=. libft_malloc.so: $(NAME) ln -sf "$(NAME)" libft_malloc.so diff --git a/README.md b/README.md index 3925fff..eb9ce03 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,12 @@ to override the functions in an already compile program you need to do this comm export LD_LIBRARY_PATH=. LD_PRELOAD=libft_malloc.so ``` +to compile a program with the lib, you have to add these parameters at the end of your compilation command (for gcc or clang): + +``` +-L -lft_malloc +``` + ## tests a test program is available at the root. to execute it do the command `make test` and then execute the program that have been compiled with `./tests` diff --git a/tests.c b/tests.c index 9796d29..08ad9c3 100644 --- a/tests.c +++ b/tests.c @@ -6,7 +6,7 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/20 17:58:16 by tomoron #+# #+# */ -/* Updated: 2025/03/20 17:58:17 by tomoron ### ########.fr */ +/* Updated: 2025/03/21 13:13:33 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -68,6 +68,7 @@ void show_alloc_ex_test() { char *data; + printf("\n\n\nSHOW_ALLOC_EX TEST:\n"); data = malloc(1020); memset(data, 0, 1020); strcpy(data, "0123456789abcdef"); @@ -82,8 +83,8 @@ int main(void) realloc_test(); show_alloc_ex_test(); - #ifdef LEAK_TEST - printf("leak_test set, allocating memory before end of program"); + #if 1 + printf("allocating memory before end of program\n"); malloc(10); malloc(50); malloc(8000);