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