]>
git.saurik.com Git - apple/objc4.git/blob - test/libraryPath.c
6 // We use DYLD_LIBRARY_PATH to run the tests against a particular copy of
7 // libobjc. If this fails somehow (path is wrong, codesigning prevents loading,
8 // etc.) then the typical result is a silent failure and we end up testing
9 // /usr/lib/libobjc.A.dylib instead. This test detects when DYLD_LIBRARY_PATH is
10 // set but libobjc isn't loaded from it.
12 char *dyldLibraryPath
= getenv("DYLD_LIBRARY_PATH");
13 testprintf("DYLD_LIBRARY_PATH is %s\n", dyldLibraryPath
);
14 if (dyldLibraryPath
!= NULL
&& strlen(dyldLibraryPath
) > 0) {
17 dyldLibraryPath
= strdup(dyldLibraryPath
);
20 int success
= dladdr((void *)objc_msgSend
, &info
);
23 testprintf("libobjc is located at %s\n", info
.dli_fname
);
25 char *cursor
= dyldLibraryPath
;
27 while ((path
= strsep(&cursor
, ":"))) {
28 char *resolved
= realpath(path
, NULL
);
29 testprintf("Resolved %s to %s\n", path
, resolved
);
30 testprintf("Comparing %s and %s\n", resolved
, info
.dli_fname
);
31 int comparison
= strncmp(resolved
, info
.dli_fname
, strlen(resolved
));
33 if (comparison
== 0) {
34 testprintf("Found a match!\n");
40 testprintf("Finished searching, foundMatch=%d\n", foundMatch
);
41 testassert(foundMatch
);