OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <unistd.h> | 7 #include <unistd.h> |
8 #if defined(OS_FREEBSD) | 8 #if defined(OS_FREEBSD) |
9 #include <sys/param.h> | 9 #include <sys/param.h> |
10 #include <sys/sysctl.h> | 10 #include <sys/sysctl.h> |
(...skipping 19 matching lines...) Expand all Loading... |
30 // The name of this file relative to the source root. This is used for checking | 30 // The name of this file relative to the source root. This is used for checking |
31 // that the source checkout is in the correct place. | 31 // that the source checkout is in the correct place. |
32 static const char kThisSourceFile[] = "base/base_paths_linux.cc"; | 32 static const char kThisSourceFile[] = "base/base_paths_linux.cc"; |
33 | 33 |
34 bool PathProviderPosix(int key, FilePath* result) { | 34 bool PathProviderPosix(int key, FilePath* result) { |
35 FilePath path; | 35 FilePath path; |
36 switch (key) { | 36 switch (key) { |
37 case base::FILE_EXE: | 37 case base::FILE_EXE: |
38 case base::FILE_MODULE: { // TODO(evanm): is this correct? | 38 case base::FILE_MODULE: { // TODO(evanm): is this correct? |
39 #if defined(OS_LINUX) | 39 #if defined(OS_LINUX) |
40 char bin_dir[PATH_MAX + 1]; | 40 FilePath bin_dir; |
41 int bin_dir_size = readlink(kSelfExe, bin_dir, PATH_MAX); | 41 if (!file_util::ReadSymbolicLink(FilePath(kSelfExe), &bin_dir)) { |
42 if (bin_dir_size < 0 || bin_dir_size > PATH_MAX) { | |
43 NOTREACHED() << "Unable to resolve " << kSelfExe << "."; | 42 NOTREACHED() << "Unable to resolve " << kSelfExe << "."; |
44 return false; | 43 return false; |
45 } | 44 } |
46 bin_dir[bin_dir_size] = 0; | 45 *result = bin_dir; |
47 *result = FilePath(bin_dir); | |
48 return true; | 46 return true; |
49 #elif defined(OS_FREEBSD) | 47 #elif defined(OS_FREEBSD) |
50 int name[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; | 48 int name[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; |
51 char bin_dir[PATH_MAX + 1]; | 49 char bin_dir[PATH_MAX + 1]; |
52 size_t length = sizeof(bin_dir); | 50 size_t length = sizeof(bin_dir); |
53 int error = sysctl(name, 4, bin_dir, &length, NULL, 0); | 51 int error = sysctl(name, 4, bin_dir, &length, NULL, 0); |
54 if (error < 0 || length == 0 || strlen(bin_dir) == 0) { | 52 if (error < 0 || length == 0 || strlen(bin_dir) == 0) { |
55 NOTREACHED() << "Unable to resolve path."; | 53 NOTREACHED() << "Unable to resolve path."; |
56 return false; | 54 return false; |
57 } | 55 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 scoped_ptr<base::Environment> env(base::Environment::Create()); | 107 scoped_ptr<base::Environment> env(base::Environment::Create()); |
110 FilePath cache_dir(base::nix::GetXDGDirectory(env.get(), "XDG_CACHE_HOME", | 108 FilePath cache_dir(base::nix::GetXDGDirectory(env.get(), "XDG_CACHE_HOME", |
111 ".cache")); | 109 ".cache")); |
112 *result = cache_dir; | 110 *result = cache_dir; |
113 return true; | 111 return true; |
114 } | 112 } |
115 return false; | 113 return false; |
116 } | 114 } |
117 | 115 |
118 } // namespace base | 116 } // namespace base |
OLD | NEW |