]> pd.if.org Git - lice/blob - tests/dl.c
autocommit for files dated 2014-11-17 20:13:34
[lice] / tests / dl.c
1 // dynamic loading
2 #include <stddef.h>
3
4 // should be good for the next ten thousand years :P
5 #define SOMAX 128
6
7 int main(void) {
8     int so = 0;
9     char buffer[32];
10     void *handle = dlopen("libc.so", 1);
11
12     if (!handle) {
13         for (so = 0; so < SOMAX; so++) {
14             snprintf(buffer, sizeof(buffer), "libc.so.%d", so);
15             if ((handle = dlopen(buffer, 1)))
16                 break;
17         }
18     }
19
20     if (!handle) {
21         printf("failed to load libc\n");
22         return 1;
23     }
24
25     // test must return 0 to succeed
26     int (*a)(int) = dlsym(handle, "exit");
27     a(0);
28
29     return 1;
30 }