blob: 0b4298a100a948e438ef66aee342404acdbcac36 [file] [log] [blame]
Steven Thomas054f2352017-05-09 14:48:37 -07001#include <dlfcn.h>
2#include <jni.h>
3
4#include <string>
5
6extern "C" {
7
8JNIEXPORT jlong JNICALL
9Java_com_google_vr_platform_Dvr_nativeLoadLibrary(
10 JNIEnv* env, jclass, jstring java_library) {
11 if (!java_library)
12 return 0;
13
14 // Convert the Java String object to a C++ null-terminated string.
15 const char* data = env->GetStringUTFChars(java_library, NULL);
16 size_t size = env->GetStringUTFLength(java_library);
17 std::string library(data, size);
18 env->ReleaseStringUTFChars(java_library, data);
19
20 // Return the handle to the requested library.
21 return reinterpret_cast<jlong>(
22 dlopen(library.c_str(), RTLD_NOW | RTLD_LOCAL));
23}
24
25} // extern "C"