#include <stdio.h>
#include <dlfcn.h>
int gInitialisersCalled = 0;
int main() {
printf("[BEGIN] dlopen-flat\n");
int result;
void* fooHandle = 0;
{
const char* path = RUN_DIR "/libfoo.dylib";
fooHandle = dlopen(path, RTLD_LAZY);
if (!fooHandle) {
printf("dlopen failed with error: %s\n", dlerror());
return 1;
}
if (gInitialisersCalled != 1) {
printf("gInitialisersCalled != 1\n");
printf("[FAIL] dlopen-flat\n");
return 1;
}
}
result = dlclose(fooHandle);
if (result != 0) {
printf("dlclose() returned %c\n", result);
printf("[FAIL] dlopen-flat\n");
return 1;
}
{
const char* path = RUN_DIR "/libfoo.dylib";
fooHandle = dlopen(path, RTLD_LAZY);
if (!fooHandle) {
printf("dlopen failed with error: %s\n", dlerror());
return 1;
}
if (gInitialisersCalled != 2) {
printf("gInitialisersCalled != 2\n");
printf("[FAIL] dlopen-flat\n");
return 1;
}
}
void* barHandle = 0;
{
const char* path = RUN_DIR "/libbar.dylib";
barHandle = dlopen(path, RTLD_LAZY);
if (!barHandle) {
printf("dlopen failed with error: %s\n", dlerror());
return 1;
}
if (gInitialisersCalled != 3) {
printf("gInitialisersCalled != 3\n");
printf("[FAIL] dlopen-flat\n");
return 1;
}
}
result = dlclose(fooHandle);
if (result != 0) {
printf("dlclose() returned %c\n", result);
printf("[FAIL] dlopen-flat\n");
return 1;
}
{
const char* path = RUN_DIR "/libfoo.dylib";
fooHandle = dlopen(path, RTLD_LAZY);
if (!fooHandle) {
printf("dlopen failed with error: %s\n", dlerror());
return 1;
}
if (gInitialisersCalled != 3) {
printf("gInitialisersCalled != 3\n");
printf("[FAIL] dlopen-flat\n");
return 1;
}
}
printf("[PASS] dlopen-flat\n");
return 0;
}