]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/dlopen-basic.dtest/main.c
dyld-625.13.tar.gz
[apple/dyld.git] / testing / test-cases / dlopen-basic.dtest / main.c
1
2 // BUILD: $CC foo.c -dynamiclib -o $BUILD_DIR/test.dylib
3 // BUILD: $CC foo.c -bundle -o $BUILD_DIR/test.bundle
4 // BUILD: $CC main.c -o $BUILD_DIR/dlopen-basic.exe
5
6 // RUN: ./dlopen-basic.exe
7
8 #include <stdio.h>
9 #include <dlfcn.h>
10
11
12 static void tryImage(const char* path)
13 {
14 printf("[BEGIN] dlopen-basic %s\n", path);
15 void* handle = dlopen(path, RTLD_LAZY);
16 if ( handle == NULL ) {
17 printf("dlerror(): %s\n", dlerror());
18 printf("[FAIL] dlopen-basic %s\n", path);
19 return;
20 }
21
22 void* sym = dlsym(handle, "foo");
23 if ( sym == NULL ) {
24 printf("dlerror(): %s\n", dlerror());
25 printf("[FAIL] dlopen-basic %s\n", path);
26 return;
27 }
28
29 int result = dlclose(handle);
30 if ( result != 0 ) {
31 printf("dlclose() returned %d, dlerror()=%s\n", result, dlerror());
32 printf("[FAIL] dlopen-basic %s\n", path);
33 return;
34 }
35
36 printf("[PASS] dlopen-basic %s\n", path);
37 }
38
39
40
41 int main()
42 {
43 tryImage("test.bundle");
44 tryImage("test.dylib");
45
46 return 0;
47 }
48