Add ability to mimic stdlib
This commit is contained in:
parent
1fd55fa7d1
commit
08703389db
3 changed files with 27 additions and 6 deletions
|
|
@ -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
|
||||
|
|
|
|||
13
axl_string.h
13
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
|
||||
|
|
|
|||
11
main.c
11
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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue