Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(331)

Side by Side Diff: base/base_paths_linux.cc

Issue 180037: Port some of the base system to FreeBSD. Extracted from... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/base_paths.h ('k') | base/native_library.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_path.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/string_piece.h" 13 #include "base/string_piece.h"
14 #include "base/sys_string_conversions.h" 14 #include "base/sys_string_conversions.h"
15 15
16 namespace base { 16 namespace base {
17 17
18 #if defined(OS_LINUX)
19 const char kSelfExe[] = "/proc/self/exe";
20 #elif defined(OS_FREEBSD)
21 const char kSelfExe[] = "/proc/curproc/file";
22 #endif
23
18 bool PathProviderLinux(int key, FilePath* result) { 24 bool PathProviderLinux(int key, FilePath* result) {
19 FilePath path; 25 FilePath path;
20 switch (key) { 26 switch (key) {
21 case base::FILE_EXE: 27 case base::FILE_EXE:
22 case base::FILE_MODULE: { // TODO(evanm): is this correct? 28 case base::FILE_MODULE: { // TODO(evanm): is this correct?
23 char bin_dir[PATH_MAX + 1]; 29 char bin_dir[PATH_MAX + 1];
24 int bin_dir_size = readlink("/proc/self/exe", bin_dir, PATH_MAX); 30 int bin_dir_size = readlink(kSelfExe, bin_dir, PATH_MAX);
25 if (bin_dir_size < 0 || bin_dir_size > PATH_MAX) { 31 if (bin_dir_size < 0 || bin_dir_size > PATH_MAX) {
26 NOTREACHED() << "Unable to resolve /proc/self/exe."; 32 NOTREACHED() << "Unable to resolve " << kSelfExe << '.';
27 return false; 33 return false;
28 } 34 }
29 bin_dir[bin_dir_size] = 0; 35 bin_dir[bin_dir_size] = 0;
30 *result = FilePath(bin_dir); 36 *result = FilePath(bin_dir);
31 return true; 37 return true;
32 } 38 }
33 case base::DIR_SOURCE_ROOT: 39 case base::DIR_SOURCE_ROOT:
34 // On linux, unit tests execute two levels deep from the source root. 40 // On linux, unit tests execute two levels deep from the source root.
35 // For example: sconsbuild/{Debug|Release}/net_unittest 41 // For example: sconsbuild/{Debug|Release}/net_unittest
36 if (!PathService::Get(base::DIR_EXE, &path)) 42 if (!PathService::Get(base::DIR_EXE, &path))
37 return false; 43 return false;
38 path = path.Append(FilePath::kParentDirectory) 44 path = path.Append(FilePath::kParentDirectory)
39 .Append(FilePath::kParentDirectory); 45 .Append(FilePath::kParentDirectory);
40 *result = path; 46 *result = path;
41 return true; 47 return true;
42 } 48 }
43 return false; 49 return false;
44 } 50 }
45 51
46 } // namespace base 52 } // namespace base
OLDNEW
« no previous file with comments | « base/base_paths.h ('k') | base/native_library.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698