#include <stdio.h>
#include <dlfcn.h>
#include <string.h>
int main()
{
printf("[BEGIN] dlopen-bad-file\n");
void* handle = dlopen(RUN_DIR "/libnota.dylib", RTLD_FIRST);
if ( handle != NULL ) {
printf("[FAIL] dlopen-bad-file should have failed on non-mach-o file %s\n", RUN_DIR "/libnota.dylib");
return 0;
}
const char* message = dlerror();
if ( (strstr(message, "mach-o") == NULL) && (strstr(message, "too short") == NULL) ) {
printf("dlerror: %s\n", message);
printf("[FAIL] dlopen-bad-file dlerror() message did not contain 'mach-o'\n");
return 0;
}
handle = dlopen(RUN_DIR, RTLD_FIRST);
if ( handle != NULL ) {
printf("[FAIL] dlopen-bad-file should have failed on dir %s\n", RUN_DIR);
return 0;
}
message = dlerror();
if ( strstr(message, "not a file") == NULL ) {
printf("dlerror: %s\n", message);
printf("[FAIL] dlopen-bad-file dlerror() message did not contain 'not a file'\n");
return 0;
}
printf("[PASS] dlopen-bad-file\n");
return 0;
}