]>
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: $SYMLINK libfoo.dylib $BUILD_DIR/libfoo-sym.dylib
6 // RUN: ./dlopen-RTLD_NOLOAD-basic.exe
13 #include "test_support.h"
15 int main(int argc
, const char* argv
[], const char* envp
[], const char* apple
[]) {
17 /// This tests that RTLD_NOLOAD finds existing dylib statically linked
19 void* handle
= dlopen(RUN_DIR
"/libfoo.dylib", RTLD_NOLOAD
);
20 if ( handle
== NULL
) {
21 FAIL("dlopen(\"libfoo.dylib\", RTLD_NOLOAD) failed but it should have worked: %s", dlerror());
23 void* sym
= dlsym(handle
, "foo");
25 FAIL("dlsym(handle, \"foo\") failed but it should have worked: %s", dlerror());
29 /// This tests that RTLD_NOLOAD verifies that non-existant dylib returns NULL
31 void* handle2
= dlopen(RUN_DIR
"/libfobbulate.dylib", RTLD_NOLOAD
);
32 if ( handle2
!= NULL
) {
33 FAIL("dlopen(\"libfobbulate.dylib\", RTLD_NOLOAD) succeeded but it should have failed");
38 /// This tests that RTLD_NOLOAD finds symlink to existing dylib
40 void* handle3
= dlopen(RUN_DIR
"/libfoo-sym.dylib", RTLD_NOLOAD
);
41 if ( handle3
== NULL
) {
42 FAIL("dlopen(\"libfoo-sym.dylib\", RTLD_NOLOAD) failed but it should have worked: %s", dlerror());
47 /// This tests that RTLD_NOLOAD of something in the dyld cache that is not yet loaded returns NULL
49 void* handle4
= dlopen("/usr/lib/libz.1.dylib", RTLD_NOLOAD
);
50 if ( handle4
!= NULL
) {
51 FAIL("dlopen(\"libz.dylib\", RTLD_NOLOAD) worked but it should have failed");