evan@chromium.org | da642ae | 2009-04-21 09:56:07 +0900 | [diff] [blame] | 1 | // 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" |
jcampan@chromium.org | d9e2be8 | 2009-06-06 07:18:09 +0900 | [diff] [blame^] | 11 | #include "base/string_util.h" |
evan@chromium.org | da642ae | 2009-04-21 09:56:07 +0900 | [diff] [blame] | 12 | |
| 13 | namespace base { |
| 14 | |
| 15 | // static |
| 16 | NativeLibrary LoadNativeLibrary(const FilePath& library_path) { |
evan@chromium.org | 9661148 | 2009-05-19 00:54:50 +0900 | [diff] [blame] | 17 | void* dl = dlopen(library_path.value().c_str(), RTLD_LAZY|RTLD_DEEPBIND); |
evan@chromium.org | da642ae | 2009-04-21 09:56:07 +0900 | [diff] [blame] | 18 | if (!dl) |
| 19 | NOTREACHED() << "dlopen failed: " << dlerror(); |
| 20 | |
| 21 | return dl; |
| 22 | } |
| 23 | |
| 24 | // static |
| 25 | void UnloadNativeLibrary(NativeLibrary library) { |
| 26 | int ret = dlclose(library); |
| 27 | if (ret < 0) |
| 28 | NOTREACHED() << "dlclose failed: " << dlerror(); |
| 29 | } |
| 30 | |
| 31 | // static |
| 32 | void* GetFunctionPointerFromNativeLibrary(NativeLibrary library, |
jcampan@chromium.org | d9e2be8 | 2009-06-06 07:18:09 +0900 | [diff] [blame^] | 33 | const char* name) { |
evan@chromium.org | da642ae | 2009-04-21 09:56:07 +0900 | [diff] [blame] | 34 | return dlsym(library, name); |
| 35 | } |
| 36 | |
jcampan@chromium.org | d9e2be8 | 2009-06-06 07:18:09 +0900 | [diff] [blame^] | 37 | // static |
| 38 | string16 GetNativeLibraryName(const string16& name) { |
| 39 | return ASCIIToUTF16("lib") + name + ASCIIToUTF16(".so"); |
| 40 | } |
| 41 | |
evan@chromium.org | da642ae | 2009-04-21 09:56:07 +0900 | [diff] [blame] | 42 | } // namespace base |