]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/dlopen-realpath.dtest/main.c
dyld-750.5.tar.gz
[apple/dyld.git] / testing / test-cases / dlopen-realpath.dtest / main.c
1
2 // BUILD: $CC main.c -o $BUILD_DIR/dlopen-realpath.exe
3 // BUILD: $SYMLINK ./IOKit.framework/IOKit $BUILD_DIR/IOKit
4 // BUILD: $SYMLINK /System/Library/Frameworks/IOKit.framework $BUILD_DIR/IOKit.framework
5
6 //FIXME: Use something besides IOKit so we do not need to copy it into the chroot
7 // R: DYLD_FALLBACK_LIBRARY_PATH=/baz ./dlopen-realpath.exe
8
9 #include <stdio.h>
10 #include <dlfcn.h>
11
12 #include "test_support.h"
13
14 static void tryImage(const char* path)
15 {
16 void* handle = dlopen(path, RTLD_LAZY);
17 if ( handle == NULL ) {
18 FAIL("dlerror(\"%s\"): %s", path, dlerror());
19 }
20
21 int result = dlclose(handle);
22 if ( result != 0 ) {
23 FAIL("dlclose(\"%s\"): %s", path, dlerror());
24 }
25 }
26
27
28
29 int main(int argc, const char* argv[], const char* envp[], const char* apple[]) {
30 tryImage("./IOKit.framework/IOKit");
31 tryImage("./././IOKit/../IOKit.framework/IOKit");
32 tryImage("./IOKit");
33
34 // Also try libSystem which has an alias in the OS to /usr/lib/libSystem.B.dylib
35 tryImage("/usr/lib/libSystem.dylib");
36
37 // Also try using non-canonical path
38 // This requires DYLD_FALLBACK_LIBRARY_PATH to be disabled, otherwise it is found that way
39 tryImage("//usr/lib/libSystem.dylib");
40 tryImage("/usr/./lib/libSystem.dylib");
41
42 PASS("Success");
43 }
44