Last active
July 27, 2020 15:52
-
-
Save routevegetable/72640c8fd26772a30faeb387630a6fac to your computer and use it in GitHub Desktop.
Macros to help you wrap things
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define DEF_WRAPPER(ret,name,...) typedef ret (*wrapped_##name##_t)(__VA_ARGS__); \ | |
static wrapped_##name##_t wrapped_##name = NULL; \ | |
ret name(__VA_ARGS__) | |
#define CALL_INNER(name, ...) (wrapped_##name ? wrapped_##name : (wrapped_##name = ((wrapped_##name##_t)dlsym(RTLD_NEXT,#name))))(__VA_ARGS__) | |
// Example: | |
// | |
//DEF_WRAPPER(ssize_t,send,int socket, const void *buffer, size_t length, int flags) | |
//{ | |
// return CALL_INNER(send, socket, buffer, length, flags); | |
//} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment