]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/dlopen-in-init2.dtest/foo.c
dyld-851.27.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 #include "test_support.h"
7
8 extern int bazInited();
9
10 static void* barHandle = NULL;
11 static void* barSymbol = NULL;
12 static int fooInited = 0;
13 static int barInited = 0;
14
15 __attribute__((constructor))
16 static void myinit(int argc, const char* argv[], const char* envp[], const char* apple[]) {
17 fooInited = 1;
18 barHandle = dlopen(RUN_DIR "/libbar.dylib", 0);
19 if ( barHandle == NULL ) {
20 FAIL("dlopen libbar.dylib: %s", dlerror());
21 }
22 barSymbol = dlsym(RTLD_DEFAULT, "barIsInited");
23 if ( barSymbol == NULL ) {
24 FAIL("dlsym libbar.dylib");
25 }
26 barInited = ((int(*)())barSymbol)();
27 }
28
29 void foo() {
30 if ( fooInited == 0 ) {
31 FAIL("Didn't init foo");
32 }
33 if ( barHandle == NULL ) {
34 FAIL("barHandle not inited");
35 }
36 if ( barSymbol == NULL ) {
37 FAIL("barSymbol not inited");
38 }
39 if ( barInited == 0 ) {
40 FAIL("Didn't init bar");
41 }
42 if ( bazInited() == 0 ) {
43 FAIL("Didn't init baz");
44 }
45 }