]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/dlopen-symlink.dtest/main.c
dyld-732.8.tar.gz
[apple/dyld.git] / testing / test-cases / dlopen-symlink.dtest / main.c
1
2 // BUILD: $CC foo.c -dynamiclib -install_name $RUN_DIR/libfoo.dylib -o $BUILD_DIR/libfoo.dylib
3 // BUILD: cd $BUILD_DIR && ln -s libfoo.dylib libfoo-symlink.dylib
4 // BUILD: $CC main.c -o $BUILD_DIR/dlopen-symlink.exe -DRUN_DIR="$RUN_DIR"
5
6 // RUN: ./dlopen-symlink.exe
7
8
9 #include <stdio.h>
10 #include <string.h>
11 #include <dlfcn.h>
12 #include <mach-o/dyld.h>
13 #include <mach-o/dyld_priv.h>
14
15
16 int main()
17 {
18 printf("[BEGIN] dlopen-symlink\n");
19
20 // call dlopen() with a path that is a symlink
21 void* handle = dlopen(RUN_DIR "/libfoo-symlink.dylib", RTLD_LAZY);
22 if ( handle == NULL ) {
23 printf("dlerror(): %s\n", dlerror());
24 printf("[FAIL] dlopen-symlink\n");
25 return 0;
26 }
27
28 // walk images to see if path was converted to real path
29 const char* foundPath = NULL;
30 int count = _dyld_image_count();
31 for (int i=0; i < count; ++i) {
32 const char* path = _dyld_get_image_name(i);
33 //printf("path[%2d]=%s\n", i, path);
34 if ( strstr(path, "libfoo") != NULL ) {
35 if ( foundPath == NULL ) {
36 foundPath = path;
37 }
38 else {
39 printf("[FAIL] dlopen-symlink: more than one libfoo found\n");
40 return 0;
41 }
42 }
43 }
44 if ( foundPath == NULL ) {
45 printf("[FAIL] dlopen-symlink: no libfoo found\n");
46 return 0;
47 }
48 if ( strstr(foundPath, "libfoo-symlink") != NULL ) {
49 printf("[FAIL] dlopen-symlink: path is symlink not real path: %s\n", foundPath);
50 return 0;
51 }
52
53 printf("[PASS] dlopen-symlink\n");
54 return 0;
55 }
56