]>
git.saurik.com Git - apple/dyld.git/blob - unit-tests/test-cases/dlopen-RTLD_LOCAL-ignore/main.c
2 * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
23 #include <stdio.h> // fprintf(), NULL
24 #include <stdlib.h> // exit(), EXIT_SUCCESS
28 #include "test.h" // PASS(), FAIL(), XPASS(), XFAIL()
32 int main(int argc
, const char* argv
[])
34 // main alreadly links with foo.dylib
35 // now dynamically link with bar.dylib
36 void* handle
= dlopen("./bar.dylib", RTLD_GLOBAL
);
37 if ( handle
== NULL
) {
38 const char* msg
= dlerror();
39 FAIL("dlopen(\"%s\", RTLD_GLOBAL) failed: %s", argv
[1], msg
);
43 // verify we can find _foo
44 void* fooSym
= dlsym(RTLD_DEFAULT
, "foo");
45 if ( fooSym
== NULL
) {
46 const char* msg
= dlerror();
47 FAIL("dlsym(RTLD_DEFAULT, \"foo\") failed: %s", msg
);
51 // verify we can find _bar
52 void* barSym
= dlsym(RTLD_DEFAULT
, "bar");
53 if ( barSym
== NULL
) {
54 const char* msg
= dlerror();
55 FAIL("dlsym(RTLD_DEFAULT, \"bar\") failed: %s", msg
);
59 // open foo privately (since it was already opened global, RTLD_LOCAL should have no effect
60 void* handleFoo
= dlopen("./foo.dylib", RTLD_LOCAL
);
61 if ( handleFoo
== NULL
) {
62 const char* msg
= dlerror();
63 FAIL("dlopen(\"%s\", RTLD_LOCAL) failed: %s", "./foo.dylib", msg
);
67 // open foo privately (since it was already opened global, RTLD_LOCAL should have no effect
68 void* handleBar
= dlopen("./bar.dylib", RTLD_LOCAL
);
69 if ( handleBar
== NULL
) {
70 const char* msg
= dlerror();
71 FAIL("dlopen(\"%s\", RTLD_LOCAL) failed: %s", "./bar.dylib", msg
);
75 // verify we can still find _foo
76 fooSym
= dlsym(RTLD_DEFAULT
, "foo");
77 if ( fooSym
== NULL
) {
78 const char* msg
= dlerror();
79 FAIL("dlsym(RTLD_DEFAULT, \"foo\") failed: %s", msg
);
83 // verify we can still find _bar
84 barSym
= dlsym(RTLD_DEFAULT
, "bar");
85 if ( barSym
== NULL
) {
86 const char* msg
= dlerror();
87 FAIL("dlsym(RTLD_DEFAULT, \"bar\") failed: %s", msg
);
91 PASS("dlopen-RTLD_LOCAL-ignore");