]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4re-core/uclibc/lib/contrib/uclibc/test/dlopen/dlstatic.c
Update
[l4.git] / l4 / pkg / l4re-core / uclibc / lib / contrib / uclibc / test / dlopen / dlstatic.c
1 #include <fcntl.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <dlfcn.h>
5 #include <stdint.h>
6
7 #define LIBNAME "libstatic.so"
8
9 int load_and_test(void)
10 {
11         void *handle;
12         int (*mystatic)(void);
13
14         handle = dlopen(LIBNAME, RTLD_LAZY);
15         if (!handle) {
16                 fprintf(stderr, "Could not open ./%s: %s\n", LIBNAME, dlerror());
17                 return 1;
18         }
19
20         mystatic = dlsym(handle, "static_test");
21         if (mystatic == NULL) {
22                 fprintf(stderr, "Could not locate symbol 'static_test': %s\n", dlerror());
23                 return 1;
24         }
25
26         if (!mystatic()) {
27                 fprintf(stderr, "mystatic() failed: static vars were not setup properly\n");
28                 return 1;
29         }
30
31         dlclose(handle);
32
33         return 0;
34 }
35
36 int main(int argc, char **argv)
37 {
38         int count = 5;
39         while (count-- > 0)
40                 if (load_and_test())
41                         return EXIT_FAILURE;
42         return EXIT_SUCCESS;
43 }