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