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