]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/dlopen-bad-file.dtest/main.c
dyld-851.27.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 #include "test_support.h"
12
13 int main(int argc, const char* argv[], const char* envp[], const char* apple[]) {
14 // try to dlopen() a text file
15 void* handle = dlopen(RUN_DIR "/libnota.dylib", RTLD_FIRST);
16 if ( handle != NULL ) {
17 FAIL("Should have failed on non-mach-o file %s", RUN_DIR "/libnota.dylib");
18 }
19 const char* message = dlerror();
20 if ( (strstr(message, "mach-o") == NULL) && (strstr(message, "too short") == NULL) ) {
21 FAIL("dlerror() message '%s' did not contain 'mach-o'", message);
22 }
23
24 // try to dlopen() a directory
25 handle = dlopen(RUN_DIR, RTLD_FIRST);
26 if ( handle != NULL ) {
27 FAIL("Should have failed on dir %s", RUN_DIR);
28 }
29 message = dlerror();
30 if ( strstr(message, "not a file") == NULL ) {
31 FAIL("dlerror() message '%s' did not contain 'not a file", message);
32 }
33
34 PASS("Success");
35 }
36