Created
September 10, 2016 15:17
-
-
Save Ravenstine/ab3c177dc2a7068de4662255670c19f4 to your computer and use it in GitHub Desktop.
Super Function in C
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
// This isn't exactly like having super-methods, especially since there are no | |
// classes or inheritances in C, but this can be useful with things like LD_PRELOAD | |
// where you want to override or proxy an existing function, and want the function | |
// to continue executing as it usually would(vs being a no-op). | |
#define _GNU_SOURCE | |
#include <dlfcn.h> | |
void glVertex3f(float x, float y, float z){ // an OpenGL function | |
static void (*super)(float, float, float) = NULL; | |
if (!super) | |
super = (void(*)(float, float, float)) dlsym(RTLD_NEXT, "glVertex3f"); | |
super(x, y, z); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment