Skip to content

Instantly share code, notes, and snippets.

@routevegetable
Last active July 27, 2020 15:52
Show Gist options
  • Save routevegetable/72640c8fd26772a30faeb387630a6fac to your computer and use it in GitHub Desktop.
Save routevegetable/72640c8fd26772a30faeb387630a6fac to your computer and use it in GitHub Desktop.
Macros to help you wrap things
#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