1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
#include <dlfcn.h>
#include <stdlib.h>
#include <stdio.h>
typedef void (*plugin_func_t) (void);
int main (int argc, char **argv)
{
void *p [10];
plugin_func_t s [10];
int i;
--argc; ++argv;
if (argc >= 10){
argc = 10;
}
for (i=0; i < argc; ++i){
p [i] = dlopen (argv [i], RTLD_LAZY);
if (p [i]){
printf ("dlopen(3) returned address: %p\n", p [i]);
}else{
fprintf (stderr, "dlopen(3) failed: %s\n", dlerror ());
return 1;
}
}
puts ("");
for (i=0; i < argc; ++i){
s [i] = (plugin_func_t) dlsym (p [i], "hello_message");
if (s [i]){
printf ("dlsym(3) returned address: %p\n", s [i]);
s [i] ();
}else{
fprintf (stderr, "dlsym(3) failed: %s\n", dlerror ());
return 1;
}
}
puts ("");
for (i=0; i < argc; ++i){
s [i] ();
}
return 0;
}
|