dyld-625.13.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: cd $BUILD_DIR && ln -s ./IOKit.framework/IOKit IOKit && ln -s /System/Library/Frameworks/IOKit.framework IOKit.framework
4
5 // RUN: DYLD_FALLBACK_LIBRARY_PATH=/baz ./dlopen-realpath.exe
6
7 #include <stdio.h>
8 #include <dlfcn.h>
9
10
11 static void tryImage(const char* path)
12 {
13 printf("[BEGIN] dlopen-realpath %s\n", path);
14 void* handle = dlopen(path, RTLD_LAZY);
15 if ( handle == NULL ) {
16 printf("dlerror(): %s\n", dlerror());
17 printf("[FAIL] dlopen-realpath %s\n", path);
18 return;
19 }
20
21 int result = dlclose(handle);
22 if ( result != 0 ) {
23 printf("dlclose(%p): %s\n", handle, dlerror());
24 printf("[FAIL] dlopen-realpath %s\n", path);
25 return;
26 }
27
28 printf("[PASS] dlopen-realpath %s\n", path);
29 }
30
31
32
33 int main()
34 {
35 tryImage("./IOKit.framework/IOKit");
36 tryImage("./././IOKit/../IOKit.framework/IOKit");
37 tryImage("./IOKit");
38
39 // Also try libSystem which has an alias in the OS to /usr/lib/libSystem.B.dylib
40 tryImage("/usr/lib/libSystem.dylib");
41
42 // Also try using non-canonical path
43 // This requires DYLD_FALLBACK_LIBRARY_PATH to be disabled, otherwise it is found that way
44 tryImage("//usr/lib/libSystem.dylib");
45 tryImage("/usr/./lib/libSystem.dylib");
46
47 return 0;
48 }
49