blob: 57c8c5dd13243d9c1044892bbf7ba48e5efee616 (
plain)
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
|
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <dlfcn.h>
#include <stdint.h>
#define LIBNAME "libstatic.so"
int load_and_test(void)
{
void *handle;
int (*mystatic)(void);
handle = dlopen(LIBNAME, RTLD_LAZY);
if (!handle) {
fprintf(stderr, "Could not open ./%s: %s\n", LIBNAME, dlerror());
return 1;
}
mystatic = dlsym(handle, "static_test");
if (mystatic == NULL) {
fprintf(stderr, "Could not locate symbol 'static_test': %s\n", dlerror());
return 1;
}
if (!mystatic()) {
fprintf(stderr, "mystatic() failed: static vars were not setup properly\n");
return 1;
}
dlclose(handle);
return 0;
}
int main(int argc, char **argv)
{
int count = 5;
while (count-- > 0)
if (load_and_test())
return EXIT_FAILURE;
return EXIT_SUCCESS;
}
|