LCA2011 version
[tridge/junkcode.git] / shlib / main.c
1 #include <stdlib.h>
2 #include <unistd.h>
3 #include <stdio.h>
4 #include <dlfcn.h>
5
6 int main(int argc, const char *argv[])
7 {
8         const char *modpath = "public/module.so";
9         void *handle;
10         const char *(*version2)(void);
11         const char *libversion(void);
12         const char *res1, *res2;
13
14         res1 = libversion();
15         printf("Direct: libversion -> %s\n", res1);
16
17         handle = dlopen(modpath, RTLD_NOW);
18         if (handle == NULL) {
19                 printf("Failed to open '%s' - %s\n",
20                        modpath, dlerror());
21                 exit(2);
22         }
23
24         version2 = dlsym(handle, "libversion");
25         if (version2 == NULL) {
26                 printf("Failed to find libversion in %s\n", modpath);
27                 exit(2);
28         }
29
30         res2 = version2();
31
32         printf("Module: libversion -> %s\n", res2);
33         if (res1 != res2) {
34                 printf("ERROR: pointer mismatch\n");
35                 exit(1);
36         }
37
38 #ifdef ENABLE_V2
39         version2 = dlsym(handle, "libversion2");
40         if (version2 == NULL) {
41                 printf("Failed to find libversion2 in %s\n", modpath);
42                 exit(2);
43         }
44
45         res2 = version2();
46
47         printf("Module: libversion -> %s\n", res2);
48         if (res1+1 != res2) {
49                 printf("ERROR: pointer mismatch\n");
50                 exit(1);
51         }
52 #endif
53         return 0;
54 }