Revert "Roll NDK to r11c and extract it into its own repository."
[android_tools.git] / ndk / sources / android / crazy_linker / tests / zoo.cpp
blobf070933b5cc84ed5f855e9002378920e24076282
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include <dlfcn.h>
6 #include <stdio.h>
8 extern "C" bool Zoo() {
9 printf("%s: Entering\n", __FUNCTION__);
10 void* bar_lib = dlopen("libbar.so", RTLD_NOW);
11 if (!bar_lib) {
12 fprintf(stderr, "Could not libbar.so: %s\n", dlerror());
13 return false;
15 printf("%s: Opened libbar.so @%p\n", __FUNCTION__, bar_lib);
17 void (*bar_func)();
19 bar_func = reinterpret_cast<void (*)()>(dlsym(bar_lib, "Bar"));
20 if (!bar_func) {
21 fprintf(stderr, "Could not find 'Bar' symbol in libbar.so\n");
22 return false;
24 printf("%s: Found 'Bar' symbol at @%p\n", __FUNCTION__, bar_func);
26 // Call it.
27 printf("%s: Calling Bar()\n", __FUNCTION__);
28 (*bar_func)();
30 printf("%s: Closing libbar.so\n", __FUNCTION__);
31 dlclose(bar_lib);
33 printf("%s: Exiting\n", __FUNCTION__);
34 return true;