OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Defines base::PathProviderMac which replaces base::PathProviderPosix for Mac | 5 // Defines base::PathProviderMac which replaces base::PathProviderPosix for Mac |
6 // in base/path_service.cc. | 6 // in base/path_service.cc. |
7 | 7 |
8 #include <dlfcn.h> | 8 #include <dlfcn.h> |
9 #import <Foundation/Foundation.h> | 9 #import <Foundation/Foundation.h> |
10 #include <mach-o/dyld.h> | 10 #include <mach-o/dyld.h> |
(...skipping 14 matching lines...) Expand all Loading... | |
25 DCHECK(path); | 25 DCHECK(path); |
26 // Executable path can have relative references ("..") depending on | 26 // Executable path can have relative references ("..") depending on |
27 // how the app was launched. | 27 // how the app was launched. |
28 uint32_t executable_length = 0; | 28 uint32_t executable_length = 0; |
29 _NSGetExecutablePath(NULL, &executable_length); | 29 _NSGetExecutablePath(NULL, &executable_length); |
30 DCHECK_GT(executable_length, 1u); | 30 DCHECK_GT(executable_length, 1u); |
31 std::string executable_path; | 31 std::string executable_path; |
32 int rv = _NSGetExecutablePath(WriteInto(&executable_path, executable_length), | 32 int rv = _NSGetExecutablePath(WriteInto(&executable_path, executable_length), |
33 &executable_length); | 33 &executable_length); |
34 DCHECK_EQ(rv, 0); | 34 DCHECK_EQ(rv, 0); |
35 *path = base::FilePath(executable_path); | 35 |
36 // _NSGetExecutablePath may return paths containing ./ or ../ which makes | |
37 // FilePath::DirName() work incorrectly, convert it to absolute path so that | |
38 // paths such as DIR_SOURCE_ROOT can work. | |
39 *path = base::MakeAbsoluteFilePath(base::FilePath(executable_path)); | |
Nico
2013/07/10 18:02:31
Hm, are you sure these paths never get persisted s
brettw
2013/08/06 04:52:06
We do want an absolute path here. We should be sur
| |
36 } | 40 } |
37 | 41 |
38 // Returns true if the module for |address| is found. |path| will contain | 42 // Returns true if the module for |address| is found. |path| will contain |
39 // the path to the module. Note that |path| may not be absolute. | 43 // the path to the module. Note that |path| may not be absolute. |
40 bool GetModulePathForAddress(base::FilePath* path, | 44 bool GetModulePathForAddress(base::FilePath* path, |
41 const void* address) WARN_UNUSED_RESULT; | 45 const void* address) WARN_UNUSED_RESULT; |
42 | 46 |
43 bool GetModulePathForAddress(base::FilePath* path, const void* address) { | 47 bool GetModulePathForAddress(base::FilePath* path, const void* address) { |
44 Dl_info info; | 48 Dl_info info; |
45 if (dladdr(address, &info) == 0) | 49 if (dladdr(address, &info) == 0) |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 return base::mac::GetUserDirectory(NSCachesDirectory, result); | 107 return base::mac::GetUserDirectory(NSCachesDirectory, result); |
104 case base::DIR_HOME: | 108 case base::DIR_HOME: |
105 *result = base::mac::NSStringToFilePath(NSHomeDirectory()); | 109 *result = base::mac::NSStringToFilePath(NSHomeDirectory()); |
106 return true; | 110 return true; |
107 default: | 111 default: |
108 return false; | 112 return false; |
109 } | 113 } |
110 } | 114 } |
111 | 115 |
112 } // namespace base | 116 } // namespace base |
OLD | NEW |