#include <stdio.h> // fprintf(), NULL
#include <stdlib.h> // exit(), EXIT_SUCCESS
#include <dlfcn.h>
#include <stdbool.h>
#include <Availability.h>
#include "test.h" // PASS(), FAIL(), XPASS(), XFAIL()
#if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && (__MAC_OS_X_VERSION_MIN_REQUIRED <= __MAC_10_5)
extern bool check_dyld_func_lookup();
typedef bool (*proc)(void);
static void trySO(const char* path)
{
void* handle = dlopen(path, RTLD_LAZY);
if ( handle == NULL ) {
FAIL("dlopen(\"%s\") failed with: %s", path, dlerror());
exit(0);
}
proc sym = (proc)dlsym(handle, "check_dyld_func_lookup");
if ( sym == NULL ) {
FAIL("dlsym(handle, \"foo\") failed");
exit(0);
}
if ( sym == &check_dyld_func_lookup )
FAIL("found same check_dyld_func_lookup as in main executable");
if ( ! (*sym)() )
FAIL("check_dyld_func_lookup failed for %s", path);
dlclose(handle);
}
#endif
int main()
{
#if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && (__MAC_OS_X_VERSION_MIN_REQUIRED <= __MAC_10_5)
if ( ! check_dyld_func_lookup() )
FAIL("check_dyld_func_lookup failed for main executable");
trySO("test.bundle");
trySO("test.dylib");
#endif
PASS("dyld-func-lookup");
return EXIT_SUCCESS;
}