OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/mac/scoped_cftyperef.h" | 11 #include "base/mac/scoped_cftyperef.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "base/threading/thread_restrictions.h" | 13 #include "base/threading/thread_restrictions.h" |
14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
15 | 15 |
16 namespace base { | 16 namespace base { |
17 | 17 |
18 // static | 18 // static |
19 NativeLibrary LoadNativeLibrary(const FilePath& library_path, | 19 NativeLibrary LoadNativeLibrary(const base::FilePath& library_path, |
20 std::string* error) { | 20 std::string* error) { |
21 // dlopen() etc. open the file off disk. | 21 // dlopen() etc. open the file off disk. |
22 if (library_path.Extension() == "dylib" || | 22 if (library_path.Extension() == "dylib" || |
23 !file_util::DirectoryExists(library_path)) { | 23 !file_util::DirectoryExists(library_path)) { |
24 void* dylib = dlopen(library_path.value().c_str(), RTLD_LAZY); | 24 void* dylib = dlopen(library_path.value().c_str(), RTLD_LAZY); |
25 if (!dylib) | 25 if (!dylib) |
26 return NULL; | 26 return NULL; |
27 NativeLibrary native_lib = new NativeLibraryStruct(); | 27 NativeLibrary native_lib = new NativeLibraryStruct(); |
28 native_lib->type = DYNAMIC_LIB; | 28 native_lib->type = DYNAMIC_LIB; |
29 native_lib->dylib = dylib; | 29 native_lib->dylib = dylib; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 } | 71 } |
72 return dlsym(library->dylib, name); | 72 return dlsym(library->dylib, name); |
73 } | 73 } |
74 | 74 |
75 // static | 75 // static |
76 string16 GetNativeLibraryName(const string16& name) { | 76 string16 GetNativeLibraryName(const string16& name) { |
77 return name + ASCIIToUTF16(".dylib"); | 77 return name + ASCIIToUTF16(".dylib"); |
78 } | 78 } |
79 | 79 |
80 } // namespace base | 80 } // namespace base |
OLD | NEW |