This source file includes following definitions.
- ToString
- LoadNativeLibrary
- UnloadNativeLibrary
- GetFunctionPointerFromNativeLibrary
- GetNativeLibraryName
#include "base/native_library.h"
#include <dlfcn.h>
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_restrictions.h"
namespace base {
std::string NativeLibraryLoadError::ToString() const {
return message;
}
NativeLibrary LoadNativeLibrary(const FilePath& library_path,
NativeLibraryLoadError* error) {
base::ThreadRestrictions::AssertIOAllowed();
void* dl = dlopen(library_path.value().c_str(), RTLD_LAZY);
if (!dl && error)
error->message = dlerror();
return dl;
}
void UnloadNativeLibrary(NativeLibrary library) {
int ret = dlclose(library);
if (ret < 0) {
DLOG(ERROR) << "dlclose failed: " << dlerror();
NOTREACHED();
}
}
void* GetFunctionPointerFromNativeLibrary(NativeLibrary library,
const char* name) {
return dlsym(library, name);
}
string16 GetNativeLibraryName(const string16& name) {
return ASCIIToUTF16("lib") + name + ASCIIToUTF16(".so");
}
}