]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/dlopen-RTLD_NOLOAD.dtest/main.c
dyld-625.13.tar.gz
[apple/dyld.git] / testing / test-cases / dlopen-RTLD_NOLOAD.dtest / main.c
1
2 // BUILD: $CC foo.c -dynamiclib -install_name $RUN_DIR/libfoo.dylib -o $BUILD_DIR/libfoo.dylib
3 // BUILD: $CC main.c $BUILD_DIR/libfoo.dylib -o $BUILD_DIR/dlopen-RTLD_NOLOAD-basic.exe
4 // BUILD: cd $BUILD_DIR && ln -s libfoo.dylib libfoo-sym.dylib
5
6 // RUN: ./dlopen-RTLD_NOLOAD-basic.exe
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <dlfcn.h>
12
13
14 int main()
15 {
16 printf("[BEGIN] dlopen-RTLD_NOLOAD-basic\n");
17
18 ///
19 /// This tests that RTLD_NOLOAD finds existing dylib statically linked
20 ///
21 void* handle = dlopen("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());
24 return 0;
25 }
26 void* sym = dlsym(handle, "foo");
27 if ( sym == NULL ) {
28 printf("[FAIL] dlopen-RTLD_NOLOAD-basic: dlsym(handle, \"foo\") failed but it should have worked: %s\n", dlerror());
29 return 0;
30 }
31
32 ///
33 /// This tests that RTLD_NOLOAD verifies that non-existant dylib returns NULL
34 ///
35 void* handle2 = dlopen("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");
38 return 0;
39 }
40
41
42 ///
43 /// This tests that RTLD_NOLOAD finds symlink to existing dylib
44 ///
45 void* handle3 = dlopen("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());
48 return 0;
49 }
50
51 printf("[PASS] dlopen-RTLD_NOLOAD-basic\n");
52 return 0;
53 }