From 08703389db92a2c52979d80ccae4dce0dc53941d Mon Sep 17 00:00:00 2001 From: NukeBird Date: Tue, 2 Dec 2025 17:57:12 +0300 Subject: [PATCH] Add ability to mimic stdlib --- axl_memory.h | 9 +++++++++ axl_string.h | 13 ++++++++++++- main.c | 11 ++++++----- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/axl_memory.h b/axl_memory.h index b551fbb..f87fd1d 100644 --- a/axl_memory.h +++ b/axl_memory.h @@ -15,4 +15,13 @@ void* axl_memcpy(void* dst, const void* src, u32 count); i32 axl_memcmp(const void* s1, const void* s2, u32 n); void axl_free(void* ptr); +#ifdef AXL_MIMIC_STDLIB +#define malloc axl_malloc +#define realloc axl_realloc +#define memset axl_memset +#define memcpy axl_memcpy +#define memcmp axl_memcmp +#define free axl_free +#endif + #endif diff --git a/axl_string.h b/axl_string.h index 6654627..3f2c586 100644 --- a/axl_string.h +++ b/axl_string.h @@ -1,6 +1,5 @@ #ifndef AXL_STRING_H #define AXL_STRING_H - #include "axl_types.h" u32 axl_strlen(const i8* s); @@ -13,4 +12,16 @@ i32 axl_strncmp(const i8* s1, const i8* s2, u32 n); const i8* axl_strchr(const i8* str, i8 c); i8* axl_strstr(const i8* str, const i8* substr); +#ifdef AXL_MIMIC_STDLIB +#define strlen axl_strlen +#define strcpy axl_strcpy +#define strncpy axl_strncpy +#define strcat axl_strcat +#define strncat axl_strncat +#define strcmp axl_strcmp +#define strncmp axl_strncmp +#define strchr axl_strchr +#define strstr axl_strstr +#endif + #endif // AXL_STRING diff --git a/main.c b/main.c index 69c38b2..c9665f9 100644 --- a/main.c +++ b/main.c @@ -1,17 +1,18 @@ +#define AXL_MIMIC_STDLIB #include "axl.h" int _start(void) { axl_init(); - void* fds = axl_malloc(83); + void* fds = malloc(83); - int* f = axl_malloc(sizeof(int)); + int* f = malloc(sizeof(int)); *f = 4; *(int*)(fds) = 4; - (void)axl_memcmp(f, fds, 4); - axl_free(fds); - axl_free(f); + (void)memcmp(f, fds, 4); + free(fds); + free(f); (void)fds; (void)f;