Chromium Code Reviews| 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/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) | |
| 23 #include <stdlib.h> | |
| 22 #endif | 24 #endif |
| 23 | 25 |
| 24 namespace base { | 26 namespace base { |
| 25 | 27 |
| 26 #if defined(OS_LINUX) | 28 #if defined(OS_LINUX) |
| 27 const char kSelfExe[] = "/proc/self/exe"; | 29 const char kSelfExe[] = "/proc/self/exe"; |
| 28 #elif defined(OS_SOLARIS) | |
| 29 const char kSelfExe[] = getexecname(); | |
|
Evan Martin
2011/06/24 17:51:18
Thanks for fixing this!
| |
| 30 #endif | 30 #endif |
| 31 | 31 |
| 32 // The name of this file relative to the source root. This is used for checking | 32 // The name of this file relative to the source root. This is used for checking |
| 33 // that the source checkout is in the correct place. | 33 // that the source checkout is in the correct place. |
| 34 static const char kThisSourceFile[] = "base/base_paths_linux.cc"; | 34 static const char kThisSourceFile[] = "base/base_paths_linux.cc"; |
| 35 | 35 |
| 36 bool PathProviderPosix(int key, FilePath* result) { | 36 bool PathProviderPosix(int key, FilePath* result) { |
| 37 FilePath path; | 37 FilePath path; |
| 38 switch (key) { | 38 switch (key) { |
| 39 case base::FILE_EXE: | 39 case base::FILE_EXE: |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 51 char bin_dir[PATH_MAX + 1]; | 51 char bin_dir[PATH_MAX + 1]; |
| 52 size_t length = sizeof(bin_dir); | 52 size_t length = sizeof(bin_dir); |
| 53 int error = sysctl(name, 4, bin_dir, &length, NULL, 0); | 53 int error = sysctl(name, 4, bin_dir, &length, NULL, 0); |
| 54 if (error < 0 || length == 0 || strlen(bin_dir) == 0) { | 54 if (error < 0 || length == 0 || strlen(bin_dir) == 0) { |
| 55 NOTREACHED() << "Unable to resolve path."; | 55 NOTREACHED() << "Unable to resolve path."; |
| 56 return false; | 56 return false; |
| 57 } | 57 } |
| 58 bin_dir[strlen(bin_dir)] = 0; | 58 bin_dir[strlen(bin_dir)] = 0; |
| 59 *result = FilePath(bin_dir); | 59 *result = FilePath(bin_dir); |
| 60 return true; | 60 return true; |
| 61 #elif defined(OS_SOLARIS) | |
| 62 char bin_dir[PATH_MAX + 1]; | |
| 63 if (realpath(getexecname(), bin_dir) == NULL) { | |
| 64 NOTREACHED() << "Unable to resolve " << getexecname() << "."; | |
| 65 return false; | |
| 66 } | |
| 67 *result = FilePath(bin_dir); | |
| 68 return true; | |
| 61 #endif | 69 #endif |
| 62 } | 70 } |
| 63 case base::DIR_SOURCE_ROOT: { | 71 case base::DIR_SOURCE_ROOT: { |
| 64 // Allow passing this in the environment, for more flexibility in build | 72 // Allow passing this in the environment, for more flexibility in build |
| 65 // tree configurations (sub-project builds, gyp --output_dir, etc.) | 73 // tree configurations (sub-project builds, gyp --output_dir, etc.) |
| 66 scoped_ptr<base::Environment> env(base::Environment::Create()); | 74 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 67 std::string cr_source_root; | 75 std::string cr_source_root; |
| 68 if (env->GetVar("CR_SOURCE_ROOT", &cr_source_root)) { | 76 if (env->GetVar("CR_SOURCE_ROOT", &cr_source_root)) { |
| 69 path = FilePath(cr_source_root); | 77 path = FilePath(cr_source_root); |
| 70 if (file_util::PathExists(path.Append(kThisSourceFile))) { | 78 if (file_util::PathExists(path.Append(kThisSourceFile))) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 scoped_ptr<base::Environment> env(base::Environment::Create()); | 117 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 110 FilePath cache_dir(base::nix::GetXDGDirectory(env.get(), "XDG_CACHE_HOME", | 118 FilePath cache_dir(base::nix::GetXDGDirectory(env.get(), "XDG_CACHE_HOME", |
| 111 ".cache")); | 119 ".cache")); |
| 112 *result = cache_dir; | 120 *result = cache_dir; |
| 113 return true; | 121 return true; |
| 114 } | 122 } |
| 115 return false; | 123 return false; |
| 116 } | 124 } |
| 117 | 125 |
| 118 } // namespace base | 126 } // namespace base |
| OLD | NEW |