How to override standard libc functions?
问题 For example, if I want to override malloc(), what's the best way to do it? Currently the simplest way I know of is: malloc.h #include <stdlib.h> #define malloc my_malloc void* my_malloc (size_t size); foobar.c #include "malloc.h" void foobar(void) { void* leak = malloc(1024); } The problem with this approach is that we now have to use "malloc.h" and can never use "stdlib.h". Is there a way around this? I'm particularly interested in importing 3rd party libraries without modifying them at all,