| 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" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 if (!file_util::ReadSymbolicLink(FilePath(kSelfExe), &bin_dir)) { | 43 if (!file_util::ReadSymbolicLink(FilePath(kSelfExe), &bin_dir)) { |
| 44 NOTREACHED() << "Unable to resolve " << kSelfExe << "."; | 44 NOTREACHED() << "Unable to resolve " << kSelfExe << "."; |
| 45 return false; | 45 return false; |
| 46 } | 46 } |
| 47 *result = bin_dir; | 47 *result = bin_dir; |
| 48 return true; | 48 return true; |
| 49 #elif defined(OS_FREEBSD) | 49 #elif defined(OS_FREEBSD) |
| 50 int name[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; | 50 int name[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; |
| 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 // Upon return, |length| is the number of bytes written to |bin_dir| |
| 54 // including the string terminator. |
| 53 int error = sysctl(name, 4, bin_dir, &length, NULL, 0); | 55 int error = sysctl(name, 4, bin_dir, &length, NULL, 0); |
| 54 if (error < 0 || length == 0 || strlen(bin_dir) == 0) { | 56 if (error < 0 || length <= 1) { |
| 55 NOTREACHED() << "Unable to resolve path."; | 57 NOTREACHED() << "Unable to resolve path."; |
| 56 return false; | 58 return false; |
| 57 } | 59 } |
| 58 bin_dir[strlen(bin_dir)] = 0; | 60 *result = FilePath(FilePath::StringType(bin_dir, length - 1)); |
| 59 *result = FilePath(bin_dir); | |
| 60 return true; | 61 return true; |
| 61 #elif defined(OS_SOLARIS) | 62 #elif defined(OS_SOLARIS) |
| 62 char bin_dir[PATH_MAX + 1]; | 63 char bin_dir[PATH_MAX + 1]; |
| 63 if (realpath(getexecname(), bin_dir) == NULL) { | 64 if (realpath(getexecname(), bin_dir) == NULL) { |
| 64 NOTREACHED() << "Unable to resolve " << getexecname() << "."; | 65 NOTREACHED() << "Unable to resolve " << getexecname() << "."; |
| 65 return false; | 66 return false; |
| 66 } | 67 } |
| 67 *result = FilePath(bin_dir); | 68 *result = FilePath(bin_dir); |
| 68 return true; | 69 return true; |
| 69 #elif defined(OS_OPENBSD) | 70 #elif defined(OS_OPENBSD) |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 scoped_ptr<base::Environment> env(base::Environment::Create()); | 122 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 122 FilePath cache_dir(base::nix::GetXDGDirectory(env.get(), "XDG_CACHE_HOME", | 123 FilePath cache_dir(base::nix::GetXDGDirectory(env.get(), "XDG_CACHE_HOME", |
| 123 ".cache")); | 124 ".cache")); |
| 124 *result = cache_dir; | 125 *result = cache_dir; |
| 125 return true; | 126 return true; |
| 126 } | 127 } |
| 127 return false; | 128 return false; |
| 128 } | 129 } |
| 129 | 130 |
| 130 } // namespace base | 131 } // namespace base |
| OLD | NEW |