]>
git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/dlopen-DYLD_LIBRARY_PATH.dtest/main.c
2 // BUILD: mkdir -p $BUILD_DIR/door1 $BUILD_DIR/door2
3 // BUILD: $CC bar.c -dynamiclib -o $BUILD_DIR/door1/libbar.dylib -install_name $RUN_DIR/libbar.dylib -DVALUE=3
4 // BUILD: $CC bar.c -dynamiclib -o $BUILD_DIR/door2/libbar.dylib -install_name $RUN_DIR/libbar.dylib -DVALUE=17
5 // BUILD: $CC foo.c -dynamiclib -o $BUILD_DIR/door1/libfoo.dylib -install_name $RUN_DIR/libfoo.dylib -DVALUE=10 $BUILD_DIR/door1/libbar.dylib
6 // BUILD: $CC foo.c -dynamiclib -o $BUILD_DIR/door2/libfoo.dylib -install_name $RUN_DIR/libfoo.dylib -DVALUE=25 $BUILD_DIR/door2/libbar.dylib
7 // BUILD: $CC main.c -o $BUILD_DIR/dlopen-DYLD_LIBRARY_PATH.exe
8 // BUILD: $DYLD_ENV_VARS_ENABLE $BUILD_DIR/dlopen-DYLD_LIBRARY_PATH.exe
10 // RUN: DYLD_LIBRARY_PATH=$RUN_DIR/door1/ ./dlopen-DYLD_LIBRARY_PATH.exe 13
11 // RUN: DYLD_LIBRARY_PATH=$RUN_DIR/door2 ./dlopen-DYLD_LIBRARY_PATH.exe 42
12 // RUN: DYLD_LIBRARY_PATH=$RUN_DIR/door3/:$RUN_DIR/door2/ ./dlopen-DYLD_LIBRARY_PATH.exe 42
18 // Program dlopen()s libfoo.dylib which was linked against libbar.dylib
19 // Neither have valid paths and must be found via DYLD_LIBRARY_PATH
20 // This test direct and indirect loading.
22 int main(int argc
, const char* argv
[])
24 const char* env
= getenv("DYLD_LIBRARY_PATH");
26 printf("[BEGIN] dlopen-DYLD_LIBRARY_PATH\n");
27 printf("[FAIL] dlopen-DYLD_LIBRARY_PATH, env not set\n");
30 const char* valueStr
= argv
[1];
31 if ( valueStr
== NULL
) {
32 printf("[BEGIN] dlopen-DYLD_LIBRARY_PATH\n");
33 printf("[FAIL] dlopen-DYLD_LIBRARY_PATH, arg1 value not set\n");
37 long value
= strtol(valueStr
, &end
, 0);
39 printf("[BEGIN] dlopen-DYLD_LIBRARY_PATH %s\n", env
);
41 void* handle
= dlopen("/bogus/libfoo.dylib", RTLD_LAZY
);
42 if ( handle
== NULL
) {
43 printf("dlerror(): %s\n", dlerror());
44 printf("[FAIL] dlopen-DYLD_LIBRARY_PATH %s\n", env
);
48 typedef int (*FooProc
)();
50 FooProc sym
= (FooProc
)dlsym(handle
, "foo");
52 printf("dlerror(): %s\n", dlerror());
53 printf("[FAIL] dlopen-DYLD_LIBRARY_PATH %s\n", env
);
57 int result
= (*sym
)();
58 if ( result
!= value
) {
59 printf("result=%d, expected %ld (str=%s)\n", result
, value
, valueStr
);
60 printf("[FAIL] dlopen-DYLD_LIBRARY_PATH %s\n", env
);
64 int r
= dlclose(handle
);
66 printf("dlclose() returned %d\n", r
);
67 printf("[FAIL] dlopen-DYLD_LIBRARY_PATH %s\n", env
);
71 void* handle2
= dlopen("/junk/libfoo.dylib", RTLD_LAZY
);
72 if ( handle2
== NULL
) {
73 printf("dlerror(): %s\n", dlerror());
74 printf("[FAIL] dlopen-DYLD_LIBRARY_PATH %s\n", env
);
80 printf("[PASS] dlopen-DYLD_LIBRARY_PATH %s\n", env
);