ipc/chromium/src/base/base_paths_linux.cc

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
michael@0 2 // Use of this source code is governed by a BSD-style license that can be
michael@0 3 // found in the LICENSE file.
michael@0 4
michael@0 5 #include "base/base_paths_linux.h"
michael@0 6
michael@0 7 #include <unistd.h>
michael@0 8
michael@0 9 #include "base/file_path.h"
michael@0 10 #include "base/file_util.h"
michael@0 11 #include "base/logging.h"
michael@0 12 #include "base/path_service.h"
michael@0 13 #include "base/string_piece.h"
michael@0 14 #include "base/sys_string_conversions.h"
michael@0 15
michael@0 16 namespace base {
michael@0 17
michael@0 18 bool PathProviderLinux(int key, FilePath* result) {
michael@0 19 FilePath path;
michael@0 20 switch (key) {
michael@0 21 case base::FILE_EXE:
michael@0 22 case base::FILE_MODULE: { // TODO(evanm): is this correct?
michael@0 23 char bin_dir[PATH_MAX + 1];
michael@0 24 int bin_dir_size = readlink("/proc/self/exe", bin_dir, PATH_MAX);
michael@0 25 if (bin_dir_size < 0 || bin_dir_size > PATH_MAX) {
michael@0 26 NOTREACHED() << "Unable to resolve /proc/self/exe.";
michael@0 27 return false;
michael@0 28 }
michael@0 29 bin_dir[bin_dir_size] = 0;
michael@0 30 *result = FilePath(bin_dir);
michael@0 31 return true;
michael@0 32 }
michael@0 33 case base::DIR_SOURCE_ROOT:
michael@0 34 // On linux, unit tests execute two levels deep from the source root.
michael@0 35 // For example: sconsbuild/{Debug|Release}/net_unittest
michael@0 36 if (!PathService::Get(base::DIR_EXE, &path))
michael@0 37 return false;
michael@0 38 path = path.Append(FilePath::kParentDirectory)
michael@0 39 .Append(FilePath::kParentDirectory);
michael@0 40 *result = path;
michael@0 41 return true;
michael@0 42 }
michael@0 43 return false;
michael@0 44 }
michael@0 45
michael@0 46 } // namespace base

mercurial