]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/dlopen-in-init3.dtest/bar.c
dyld-732.8.tar.gz
[apple/dyld.git] / testing / test-cases / dlopen-in-init3.dtest / bar.c
1
2 #include <dlfcn.h>
3 #include <stdio.h>
4 #include <unistd.h>
5
6 static void* bazHandle = NULL;
7 static void* bazSymbol = NULL;
8 static int barInited = 0;
9 static int bazInited = 0;
10
11 __attribute__((constructor))
12 static void myinit()
13 {
14 barInited = 1;
15 bazHandle = dlopen(RUN_DIR "/libbaz.dylib", 0);
16 if ( bazHandle == NULL ) {
17 printf("[FAIL] dlopen-in-init3, dlopen libbaz.dylib: %s\n", dlerror());
18 return;
19 }
20 bazSymbol = dlsym(RTLD_DEFAULT, "bazIsInited");
21 if ( bazSymbol == NULL ) {
22 printf("[FAIL] dlopen-in-init3, dlsym libbaz.dylib\n");
23 return;
24 }
25 bazInited = ((int(*)())bazSymbol)();
26 }
27
28 int bar() {
29 if ( barInited == 0 ) {
30 printf("[FAIL] dlopen-in-init3, didn't init bar\n");
31 return 1;
32 }
33 if ( bazHandle == NULL ) {
34 return 1;
35 }
36 if ( bazSymbol == NULL ) {
37 return 1;
38 }
39 if ( bazInited == 0 ) {
40 printf("[FAIL] dlopen-in-init3, didn't init bar\n");
41 return 1;
42 }
43 return 0;
44 }