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 #include <mach-o/getsect.h> | 8 #include <mach-o/getsect.h> |
9 | 9 |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 reinterpret_cast<const struct mach_header*>(info.dli_fbase), | 38 reinterpret_cast<const struct mach_header*>(info.dli_fbase), |
39 SEG_OBJC, "__image_info"); | 39 SEG_OBJC, "__image_info"); |
40 #endif | 40 #endif |
41 return section == NULL ? OBJC_NOT_PRESENT : OBJC_PRESENT; | 41 return section == NULL ? OBJC_NOT_PRESENT : OBJC_PRESENT; |
42 } | 42 } |
43 | 43 |
44 // static | 44 // static |
45 NativeLibrary LoadNativeLibrary(const base::FilePath& library_path, | 45 NativeLibrary LoadNativeLibrary(const base::FilePath& library_path, |
46 std::string* error) { | 46 std::string* error) { |
47 // dlopen() etc. open the file off disk. | 47 // dlopen() etc. open the file off disk. |
48 if (library_path.Extension() == "dylib" || | 48 if (library_path.Extension() == "dylib" || !DirectoryExists(library_path)) { |
49 !file_util::DirectoryExists(library_path)) { | |
50 void* dylib = dlopen(library_path.value().c_str(), RTLD_LAZY); | 49 void* dylib = dlopen(library_path.value().c_str(), RTLD_LAZY); |
51 if (!dylib) | 50 if (!dylib) |
52 return NULL; | 51 return NULL; |
53 NativeLibrary native_lib = new NativeLibraryStruct(); | 52 NativeLibrary native_lib = new NativeLibraryStruct(); |
54 native_lib->type = DYNAMIC_LIB; | 53 native_lib->type = DYNAMIC_LIB; |
55 native_lib->dylib = dylib; | 54 native_lib->dylib = dylib; |
56 native_lib->objc_status = OBJC_UNKNOWN; | 55 native_lib->objc_status = OBJC_UNKNOWN; |
57 return native_lib; | 56 return native_lib; |
58 } | 57 } |
59 base::ScopedCFTypeRef<CFURLRef> url(CFURLCreateFromFileSystemRepresentation( | 58 base::ScopedCFTypeRef<CFURLRef> url(CFURLCreateFromFileSystemRepresentation( |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 116 |
118 return function_pointer; | 117 return function_pointer; |
119 } | 118 } |
120 | 119 |
121 // static | 120 // static |
122 string16 GetNativeLibraryName(const string16& name) { | 121 string16 GetNativeLibraryName(const string16& name) { |
123 return name + ASCIIToUTF16(".dylib"); | 122 return name + ASCIIToUTF16(".dylib"); |
124 } | 123 } |
125 | 124 |
126 } // namespace base | 125 } // namespace base |
OLD | NEW |