]>
git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/dlopen-DYLD_LIBRARY_PATH.dtest/main.c
2 // BUILD: $CC bar.c -dynamiclib -o $BUILD_DIR/door1/libbar.dylib -install_name $RUN_DIR/libbar.dylib -DVALUE=3
3 // BUILD: $CC bar.c -dynamiclib -o $BUILD_DIR/door2/libbar.dylib -install_name $RUN_DIR/libbar.dylib -DVALUE=17
4 // BUILD: $CC foo.c -dynamiclib -o $BUILD_DIR/door1/libfoo.dylib -install_name $RUN_DIR/libfoo.dylib -DVALUE=10 $BUILD_DIR/door1/libbar.dylib
5 // BUILD: $CC foo.c -dynamiclib -o $BUILD_DIR/door2/libfoo.dylib -install_name $RUN_DIR/libfoo.dylib -DVALUE=25 $BUILD_DIR/door2/libbar.dylib
6 // BUILD: $CC main.c -o $BUILD_DIR/dlopen-DYLD_LIBRARY_PATH.exe
7 // BUILD: $DYLD_ENV_VARS_ENABLE $BUILD_DIR/dlopen-DYLD_LIBRARY_PATH.exe
9 // RUN: DYLD_LIBRARY_PATH=$RUN_DIR/door1/ ./dlopen-DYLD_LIBRARY_PATH.exe 13
10 // RUN: DYLD_LIBRARY_PATH=$RUN_DIR/door2 ./dlopen-DYLD_LIBRARY_PATH.exe 42
11 // RUN: DYLD_LIBRARY_PATH=$RUN_DIR/door3/:$RUN_DIR/door2/ ./dlopen-DYLD_LIBRARY_PATH.exe 42
17 #include "test_support.h"
19 // Program dlopen()s libfoo.dylib which was linked against libbar.dylib
20 // Neither have valid paths and must be found via DYLD_LIBRARY_PATH
21 // This test direct and indirect loading.
23 int main(int argc
, const char* argv
[], const char* envp
[], const char* apple
[]) {
24 const char* env
= getenv("DYLD_LIBRARY_PATH");
28 const char* valueStr
= argv
[1];
29 if ( valueStr
== NULL
) {
30 FAIL("arg1 value not set");
33 long value
= strtol(valueStr
, &end
, 0);
36 void* handle
= dlopen("/bogus/libfoo.dylib", RTLD_LAZY
);
37 if ( handle
== NULL
) {
38 FAIL("dlerror(\"/bogus/libfoo.dylib\"): %s", dlerror());
41 typedef int (*FooProc
)();
43 FooProc sym
= (FooProc
)dlsym(handle
, "foo");
45 FAIL("dlerror(): %s", dlerror());
48 int result
= (*sym
)();
49 if ( result
!= value
) {
50 FAIL("result=%d, expected %ld (str=%s)", result
, value
, valueStr
);
53 int r
= dlclose(handle
);
55 FAIL("dlclose() returned %d", r
);
58 void* handle2
= dlopen("/junk/libfoo.dylib", RTLD_LAZY
);
59 if ( handle2
== NULL
) {
60 FAIL("dlerror(\"/junk/libfoo.dylib\"): %s", dlerror());