]>
git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/dlopen-RTLD_NOLOAD.dtest/main.c
2 // BUILD: $CC foo.c -dynamiclib -install_name $RUN_DIR/libfoo.dylib -o $BUILD_DIR/libfoo.dylib
3 // BUILD: $CC main.c -DRUN_DIR="$RUN_DIR" $BUILD_DIR/libfoo.dylib -o $BUILD_DIR/dlopen-RTLD_NOLOAD-basic.exe
4 // BUILD: cd $BUILD_DIR && ln -s libfoo.dylib libfoo-sym.dylib
6 // RUN: ./dlopen-RTLD_NOLOAD-basic.exe
16 printf("[BEGIN] dlopen-RTLD_NOLOAD-basic\n");
19 /// This tests that RTLD_NOLOAD finds existing dylib statically linked
21 void* handle
= dlopen(RUN_DIR
"/libfoo.dylib", RTLD_NOLOAD
);
22 if ( handle
== NULL
) {
23 printf("[FAIL] dlopen-RTLD_NOLOAD-basic: dlopen(libfoo.dylib, RTLD_NOLOAD) failed but it should have worked: %s\n", dlerror());
26 void* sym
= dlsym(handle
, "foo");
28 printf("[FAIL] dlopen-RTLD_NOLOAD-basic: dlsym(handle, \"foo\") failed but it should have worked: %s\n", dlerror());
33 /// This tests that RTLD_NOLOAD verifies that non-existant dylib returns NULL
35 void* handle2
= dlopen(RUN_DIR
"/libfobbulate.dylib", RTLD_NOLOAD
);
36 if ( handle2
!= NULL
) {
37 printf("[FAIL] dlopen-RTLD_NOLOAD-basic: dlopen(libfobbulate.dylib, RTLD_NOLOAD) succeeded but it should have failed\n");
43 /// This tests that RTLD_NOLOAD finds symlink to existing dylib
45 void* handle3
= dlopen(RUN_DIR
"/libfoo-sym.dylib", RTLD_NOLOAD
);
46 if ( handle3
== NULL
) {
47 printf("[FAIL] dlopen-RTLD_NOLOAD-basic: dlopen(libfoo-sym.dylib, RTLD_NOLOAD) failed but it should have worked: %s\n", dlerror());
53 /// This tests that RTLD_NOLOAD of something in the dyld cache that is not yet loaded returns NULL
55 void* handle4
= dlopen("/usr/lib/libz.1.dylib", RTLD_NOLOAD
);
56 if ( handle4
!= NULL
) {
57 printf("[FAIL] dlopen-RTLD_NOLOAD-basic: dlopen(libz.dylib, RTLD_NOLOAD) worked but it should have failed\n");
62 printf("[PASS] dlopen-RTLD_NOLOAD-basic\n");