All pastes #471462 Raw Edit

Stuff

public c v1 · immutable
·published 2007-05-04 22:19 UTC
rendered paste body
#include <stdio.h>#include <dlfcn.h>#include <string.h>int main(int argc, char ** argv){	char *soname;	char *fname;	char *error ;	void (*f)(void);	double (*f2)(double);	if ( argc != 3)	{		fprintf(stdout, "Usage: %s lib.so function\n", argv[0]);		return 0 ;	}	else	{		soname = argv[1] ;		fname = argv[2]);	}	void * handle = dlopen(soname, RTLD_LAZY);	if ( !handle )	{		fprintf(stderr, "Error opening %s\n", soname);		fprintf(stderr, "%s\n", dlerror());		return -1 ;	}	dlerror(); /* clear an existing error */	*(void **) (&f) = dlsym(handle, fname);	if ( (error = dlerror()) != NULL )	{		fprintf(stderr, "Error calling function %s\n", fname);		fprintf(stderr, "%s\n", error);		dlclose(handle);		return -1;	}	(*f)();	dlclose(handle);	return 0 ;}