-
-
Save rightfold/2046d79c64fe8ea60256 to your computer and use it in GitHub Desktop.
This file contains 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
typedef int (*intfunc)(int); | |
typedef void (*pfunc)(int*, int); | |
pfunc partial(intfunc fin) | |
{ | |
pfunc f; | |
static int idx = 0; | |
char cc[256], lib[256]; | |
FILE *fp; | |
sprintf(lib, "/tmp/stuff%d.so", ++idx); | |
sprintf(cc, "cc -pipe -x c -shared -o %s -", lib); | |
fp = popen(cc, "w"); | |
fprintf(fp, "#define t typedef\xat int _i,*i;t _i(*__)(_i);__ p =(__)%p;" | |
"void _(i _1, _i l){while(--l>-1)l[_1]=p(l[_1]);}", fin); | |
fclose(fp); | |
*(void **)(&f) = dlsym(dlopen(lib, RTLD_LAZY), "_"); | |
unlink(lib); | |
return f; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment