]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/dlopen-symlink.dtest/main.c
dyld-750.5.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: $SYMLINK libfoo.dylib $BUILD_DIR/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 #include "test_support.h"
16
17 int main(int argc, const char* argv[], const char* envp[], const char* apple[]) {
18 // call dlopen() with a path that is a symlink
19 void* handle = dlopen(RUN_DIR "/libfoo-symlink.dylib", RTLD_LAZY);
20 if ( handle == NULL ) {
21 FAIL("dlerror(): %s", dlerror());
22 }
23
24 // walk images to see if path was converted to real path
25 const char* foundPath = NULL;
26 int count = _dyld_image_count();
27 for (int i=0; i < count; ++i) {
28 const char* path = _dyld_get_image_name(i);
29 LOG("path[%2d]=%s", i, path);
30 if ( strstr(path, "libfoo") != NULL ) {
31 if ( foundPath == NULL ) {
32 foundPath = path;
33 }
34 else {
35 FAIL("More than one libfoo found");
36 }
37 }
38 }
39 if ( foundPath == NULL ) {
40 FAIL("No libfoo found");
41 }
42 if ( strstr(foundPath, "libfoo-symlink") != NULL ) {
43 FAIL("Path is symlink not real path: %s", foundPath);
44 }
45
46 PASS("Success");
47 }
48