| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/native_library.h" | 5 #include "base/native_library.h" |
| 6 | 6 |
| 7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
| 8 | 8 |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 | 12 |
| 13 namespace base { | 13 namespace base { |
| 14 | 14 |
| 15 // static | 15 // static |
| 16 NativeLibrary LoadNativeLibrary(const FilePath& library_path) { | 16 NativeLibrary LoadNativeLibrary(const FilePath& library_path) { |
| 17 void* dl = dlopen(library_path.value().c_str(), RTLD_LAZY); | 17 void* dl = dlopen(library_path.value().c_str(), RTLD_LAZY); |
| 18 if (!dl) { | 18 if (!dl) { |
| 19 std::string error_message = dlerror(); | 19 LOG(ERROR) << "dlopen failed when trying to open " << library_path.value() |
| 20 // Some obsolete plugins depend on libxul or libxpcom. | 20 << ": " << dlerror(); |
| 21 // Ignore the error messages when failing to load these. | |
| 22 if (error_message.find("libxul.so") == std::string::npos && | |
| 23 error_message.find("libxpcom.so") == std::string::npos) { | |
| 24 LOG(ERROR) << "dlopen failed when trying to open " << library_path.value() | |
| 25 << ": " << error_message; | |
| 26 } | |
| 27 } | 21 } |
| 28 | 22 |
| 29 return dl; | 23 return dl; |
| 30 } | 24 } |
| 31 | 25 |
| 32 // static | 26 // static |
| 33 void UnloadNativeLibrary(NativeLibrary library) { | 27 void UnloadNativeLibrary(NativeLibrary library) { |
| 34 int ret = dlclose(library); | 28 int ret = dlclose(library); |
| 35 if (ret < 0) { | 29 if (ret < 0) { |
| 36 LOG(ERROR) << "dlclose failed: " << dlerror(); | 30 LOG(ERROR) << "dlclose failed: " << dlerror(); |
| 37 NOTREACHED(); | 31 NOTREACHED(); |
| 38 } | 32 } |
| 39 } | 33 } |
| 40 | 34 |
| 41 // static | 35 // static |
| 42 void* GetFunctionPointerFromNativeLibrary(NativeLibrary library, | 36 void* GetFunctionPointerFromNativeLibrary(NativeLibrary library, |
| 43 const char* name) { | 37 const char* name) { |
| 44 return dlsym(library, name); | 38 return dlsym(library, name); |
| 45 } | 39 } |
| 46 | 40 |
| 47 // static | 41 // static |
| 48 string16 GetNativeLibraryName(const string16& name) { | 42 string16 GetNativeLibraryName(const string16& name) { |
| 49 return ASCIIToUTF16("lib") + name + ASCIIToUTF16(".so"); | 43 return ASCIIToUTF16("lib") + name + ASCIIToUTF16(".so"); |
| 50 } | 44 } |
| 51 | 45 |
| 52 } // namespace base | 46 } // namespace base |
| OLD | NEW |