]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/dlopen-bad-file.dtest/main.c
dyld-551.4.tar.gz
[apple/dyld.git] / testing / test-cases / dlopen-bad-file.dtest / main.c
1
2 // BUILD: cp bad.txt $BUILD_DIR/libnota.dylib
3 // BUILD: $CC main.c -o $BUILD_DIR/dlopen-bad-file.exe -DRUN_DIR="$RUN_DIR"
4
5 // RUN: ./dlopen-bad-file.exe
6
7 #include <stdio.h>
8 #include <dlfcn.h>
9 #include <string.h>
10
11
12
13 int main()
14 {
15 printf("[BEGIN] dlopen-bad-file\n");
16
17 // try to dlopen() a text file
18 void* handle = dlopen(RUN_DIR "/libnota.dylib", RTLD_FIRST);
19 if ( handle != NULL ) {
20 printf("[FAIL] dlopen-bad-file should have failed on non-mach-o file %s\n", RUN_DIR "/libnota.dylib");
21 return 0;
22 }
23 const char* message = dlerror();
24 if ( (strstr(message, "mach-o") == NULL) && (strstr(message, "too short") == NULL) ) {
25 printf("dlerror: %s\n", message);
26 printf("[FAIL] dlopen-bad-file dlerror() message did not contain 'mach-o'\n");
27 return 0;
28 }
29
30 // try to dlopen() a directory
31 handle = dlopen(RUN_DIR, RTLD_FIRST);
32 if ( handle != NULL ) {
33 printf("[FAIL] dlopen-bad-file should have failed on dir %s\n", RUN_DIR);
34 return 0;
35 }
36 message = dlerror();
37 if ( strstr(message, "not a file") == NULL ) {
38 printf("dlerror: %s\n", message);
39 printf("[FAIL] dlopen-bad-file dlerror() message did not contain 'not a file'\n");
40 return 0;
41 }
42
43 printf("[PASS] dlopen-bad-file\n");
44
45 return 0;
46 }
47