OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/base_paths_linux.h" | 5 #include "base/base_paths_linux.h" |
6 | 6 |
7 #include <unistd.h> | 7 #include <unistd.h> |
8 | 8 |
| 9 #include "base/file_path.h" |
9 #include "base/file_util.h" | 10 #include "base/file_util.h" |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "base/path_service.h" | 12 #include "base/path_service.h" |
12 #include "base/string_piece.h" | 13 #include "base/string_piece.h" |
13 #include "base/sys_string_conversions.h" | 14 #include "base/sys_string_conversions.h" |
14 | 15 |
15 namespace base { | 16 namespace base { |
16 | 17 |
17 bool PathProviderLinux(int key, std::wstring* result) { | 18 bool PathProviderLinux(int key, std::wstring* result) { |
18 std::wstring cur; | 19 FilePath path; |
19 switch (key) { | 20 switch (key) { |
20 case base::FILE_EXE: | 21 case base::FILE_EXE: |
21 case base::FILE_MODULE: { // TODO(evanm): is this correct? | 22 case base::FILE_MODULE: { // TODO(evanm): is this correct? |
22 char bin_dir[PATH_MAX + 1]; | 23 char bin_dir[PATH_MAX + 1]; |
23 int bin_dir_size = readlink("/proc/self/exe", bin_dir, PATH_MAX); | 24 int bin_dir_size = readlink("/proc/self/exe", bin_dir, PATH_MAX); |
24 if (bin_dir_size < 0 || bin_dir_size > PATH_MAX) { | 25 if (bin_dir_size < 0 || bin_dir_size > PATH_MAX) { |
25 NOTREACHED() << "Unable to resolve /proc/self/exe."; | 26 NOTREACHED() << "Unable to resolve /proc/self/exe."; |
26 return false; | 27 return false; |
27 } | 28 } |
28 bin_dir[bin_dir_size] = 0; | 29 bin_dir[bin_dir_size] = 0; |
29 *result = base::SysNativeMBToWide(bin_dir); | 30 *result = base::SysNativeMBToWide(bin_dir); |
30 return true; | 31 return true; |
31 } | 32 } |
32 case base::DIR_SOURCE_ROOT: | 33 case base::DIR_SOURCE_ROOT: |
33 // On linux, unit tests execute two levels deep from the source root. | 34 // On linux, unit tests execute two levels deep from the source root. |
34 // For example: chrome/{Debug|Hammer}/net_unittest | 35 // For example: chrome/{Debug|Hammer}/net_unittest |
35 PathService::Get(base::DIR_EXE, &cur); | 36 if (!PathService::Get(base::DIR_EXE, &path)) |
36 file_util::UpOneDirectory(&cur); | 37 return false; |
37 file_util::UpOneDirectory(&cur); | 38 path = path.Append(FilePath::kParentDirectory) |
38 *result = cur; | 39 .Append(FilePath::kParentDirectory); |
| 40 *result = path.ToWStringHack(); |
39 return true; | 41 return true; |
40 } | 42 } |
41 return false; | 43 return false; |
42 } | 44 } |
43 | 45 |
44 } // namespace base | 46 } // namespace base |
45 | 47 |
OLD | NEW |