dyld-625.13.tar.gz
[apple/dyld.git] / testing / test-cases / env-DYLD_LIBRARY_PATH-cache.dtest / main.c
1
2 // BUILD: mkdir -p $BUILD_DIR/override
3 // BUILD: $CC myzlib.c -dynamiclib -o $BUILD_DIR/override/libz.1.dylib -install_name /usr/lib/libz.1.dylib -compatibility_version 1.0 -framework CoreFoundation
4 // BUILD: $CC main.c -o $BUILD_DIR/main.exe -lz
5 // BUILD: $DYLD_ENV_VARS_ENABLE $BUILD_DIR/main.exe
6
7 // RUN: ./main.exe
8 // RUN: DYLD_LIBRARY_PATH=$RUN_DIR/override/ ./main.exe
9
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <zlib.h>
14 #include <stdbool.h>
15
16 // The test here is to override libz.1.dylib which is in the dyld cache with our own implementation.
17
18 int main()
19 {
20 bool expectMyDylib = (getenv("DYLD_LIBRARY_PATH") != NULL);
21
22 printf("[BEGIN] env-DYLD_LIBRARY_PATH-cache, %s\n", expectMyDylib ? "my" : "os");
23
24 bool usingMyDylib = (strcmp(zlibVersion(), "my") == 0);
25
26 if ( usingMyDylib == expectMyDylib )
27 printf("[PASS] env-DYLD_LIBRARY_PATH-cache, %s\n", expectMyDylib ? "my" : "os");
28 else
29 printf("[FAIL] env-DYLD_LIBRARY_PATH-cache, %s\n", expectMyDylib ? "my" : "os");
30
31 return 0;
32 }
33