]>
git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/dlopen-symlink.dtest/main.c
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"
6 // RUN: ./dlopen-symlink.exe
12 #include <mach-o/dyld.h>
13 #include <mach-o/dyld_priv.h>
18 printf("[BEGIN] dlopen-symlink\n");
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");
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
) {
39 printf("[FAIL] dlopen-symlink: more than one libfoo found\n");
44 if ( foundPath
== NULL
) {
45 printf("[FAIL] dlopen-symlink: no libfoo found\n");
48 if ( strstr(foundPath
, "libfoo-symlink") != NULL
) {
49 printf("[FAIL] dlopen-symlink: path is symlink not real path: %s\n", foundPath
);
53 printf("[PASS] dlopen-symlink\n");