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 #include "base/base_paths.h" | 5 #include "base/base_paths.h" |
6 | 6 |
7 #include <ostream> | 7 #include <ostream> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 #include "base/environment.h" | 11 #include "base/environment.h" |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
17 #include "base/nix/xdg_util.h" | 17 #include "base/nix/xdg_util.h" |
18 | 18 |
19 #if defined(OS_FREEBSD) | 19 #if defined(OS_FREEBSD) |
20 #include <sys/param.h> | 20 #include <sys/param.h> |
21 #include <sys/sysctl.h> | 21 #include <sys/sysctl.h> |
22 #elif defined(OS_SOLARIS) | 22 #elif defined(OS_SOLARIS) |
23 #include <stdlib.h> | 23 #include <stdlib.h> |
24 #endif | 24 #endif |
25 | 25 |
26 #if defined(OS_LINUX) | |
27 #include "base/process_util.h" | |
brettw
2012/09/14 21:56:52
I'd put this above and not in an ifdef.
Lei Zhang
2012/09/14 22:00:54
Done.
| |
28 #endif | |
29 | |
26 namespace base { | 30 namespace base { |
27 | 31 |
28 #if defined(OS_LINUX) | |
29 const char kSelfExe[] = "/proc/self/exe"; | |
30 #endif | |
31 | |
32 bool PathProviderPosix(int key, FilePath* result) { | 32 bool PathProviderPosix(int key, FilePath* result) { |
33 FilePath path; | 33 FilePath path; |
34 switch (key) { | 34 switch (key) { |
35 case base::FILE_EXE: | 35 case base::FILE_EXE: |
36 case base::FILE_MODULE: { // TODO(evanm): is this correct? | 36 case base::FILE_MODULE: { // TODO(evanm): is this correct? |
37 #if defined(OS_LINUX) | 37 #if defined(OS_LINUX) |
38 FilePath bin_dir; | 38 FilePath bin_dir; |
39 if (!file_util::ReadSymbolicLink(FilePath(kSelfExe), &bin_dir)) { | 39 if (!file_util::ReadSymbolicLink(FilePath(kProcSelfExe), &bin_dir)) { |
40 NOTREACHED() << "Unable to resolve " << kSelfExe << "."; | 40 NOTREACHED() << "Unable to resolve " << kProcSelfExe << "."; |
41 return false; | 41 return false; |
42 } | 42 } |
43 *result = bin_dir; | 43 *result = bin_dir; |
44 return true; | 44 return true; |
45 #elif defined(OS_FREEBSD) | 45 #elif defined(OS_FREEBSD) |
46 int name[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; | 46 int name[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; |
47 char bin_dir[PATH_MAX + 1]; | 47 char bin_dir[PATH_MAX + 1]; |
48 size_t length = sizeof(bin_dir); | 48 size_t length = sizeof(bin_dir); |
49 // Upon return, |length| is the number of bytes written to |bin_dir| | 49 // Upon return, |length| is the number of bytes written to |bin_dir| |
50 // including the string terminator. | 50 // including the string terminator. |
51 int error = sysctl(name, 4, bin_dir, &length, NULL, 0); | 51 int error = sysctl(name, 4, bin_dir, &length, NULL, 0); |
52 if (error < 0 || length <= 1) { | 52 if (error < 0 || length <= 1) { |
53 NOTREACHED() << "Unable to resolve path."; | 53 NOTREACHED() << "Unable to resolve path."; |
54 return false; | 54 return false; |
55 } | 55 } |
56 *result = FilePath(FilePath::StringType(bin_dir, length - 1)); | 56 *result = FilePath(FilePath::StringType(bin_dir, length - 1)); |
57 return true; | 57 return true; |
58 #elif defined(OS_SOLARIS) | 58 #elif defined(OS_SOLARIS) |
59 char bin_dir[PATH_MAX + 1]; | 59 char bin_dir[PATH_MAX + 1]; |
60 if (realpath(getexecname(), bin_dir) == NULL) { | 60 if (realpath(getexecname(), bin_dir) == NULL) { |
61 NOTREACHED() << "Unable to resolve " << getexecname() << "."; | 61 NOTREACHED() << "Unable to resolve " << getexecname() << "."; |
62 return false; | 62 return false; |
63 } | 63 } |
64 *result = FilePath(bin_dir); | 64 *result = FilePath(bin_dir); |
65 return true; | 65 return true; |
66 #elif defined(OS_OPENBSD) | 66 #elif defined(OS_OPENBSD) |
67 // There is currently no way to get the executable path on OpenBSD | 67 // There is currently no way to get the executable path on OpenBSD |
68 char *cpath; | 68 char* cpath; |
69 if ((cpath = getenv("CHROME_EXE_PATH")) != NULL) | 69 if ((cpath = getenv("CHROME_EXE_PATH")) != NULL) |
70 *result = FilePath(cpath); | 70 *result = FilePath(cpath); |
71 else | 71 else |
72 *result = FilePath("/usr/local/chrome/chrome"); | 72 *result = FilePath("/usr/local/chrome/chrome"); |
73 return true; | 73 return true; |
74 #endif | 74 #endif |
75 } | 75 } |
76 case base::DIR_SOURCE_ROOT: { | 76 case base::DIR_SOURCE_ROOT: { |
77 // Allow passing this in the environment, for more flexibility in build | 77 // Allow passing this in the environment, for more flexibility in build |
78 // tree configurations (sub-project builds, gyp --output_dir, etc.) | 78 // tree configurations (sub-project builds, gyp --output_dir, etc.) |
(...skipping 29 matching lines...) Expand all Loading... | |
108 } | 108 } |
109 case base::DIR_HOME: { | 109 case base::DIR_HOME: { |
110 *result = file_util::GetHomeDir(); | 110 *result = file_util::GetHomeDir(); |
111 return true; | 111 return true; |
112 } | 112 } |
113 } | 113 } |
114 return false; | 114 return false; |
115 } | 115 } |
116 | 116 |
117 } // namespace base | 117 } // namespace base |
OLD | NEW |