blob: 39221c15cbc4dc38673683a2d1ed1c82d756b857 [file] [log] [blame]
[email protected]f38e25f2009-04-21 00:56:071// Copyright (c) 2009 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.
4
5#include "base/native_library.h"
6
7#include <dlfcn.h>
8
9#include "base/file_path.h"
10#include "base/logging.h"
[email protected]108c2a12009-06-05 22:18:0911#include "base/string_util.h"
[email protected]f38e25f2009-04-21 00:56:0712
13namespace base {
14
15// static
16NativeLibrary LoadNativeLibrary(const FilePath& library_path) {
[email protected]d0001a5d2009-05-18 15:54:5017 void* dl = dlopen(library_path.value().c_str(), RTLD_LAZY|RTLD_DEEPBIND);
[email protected]f38e25f2009-04-21 00:56:0718 if (!dl)
19 NOTREACHED() << "dlopen failed: " << dlerror();
20
21 return dl;
22}
23
24// static
25void UnloadNativeLibrary(NativeLibrary library) {
26 int ret = dlclose(library);
27 if (ret < 0)
28 NOTREACHED() << "dlclose failed: " << dlerror();
29}
30
31// static
32void* GetFunctionPointerFromNativeLibrary(NativeLibrary library,
[email protected]108c2a12009-06-05 22:18:0933 const char* name) {
[email protected]f38e25f2009-04-21 00:56:0734 return dlsym(library, name);
35}
36
[email protected]108c2a12009-06-05 22:18:0937// static
38string16 GetNativeLibraryName(const string16& name) {
39 return ASCIIToUTF16("lib") + name + ASCIIToUTF16(".so");
40}
41
[email protected]f38e25f2009-04-21 00:56:0742} // namespace base