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.

     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
     3 // found in the LICENSE file.
     5 #include "base/base_paths_linux.h"
     7 #include <unistd.h>
     9 #include "base/file_path.h"
    10 #include "base/file_util.h"
    11 #include "base/logging.h"
    12 #include "base/path_service.h"
    13 #include "base/string_piece.h"
    14 #include "base/sys_string_conversions.h"
    16 namespace base {
    18 bool PathProviderLinux(int key, FilePath* result) {
    19   FilePath path;
    20   switch (key) {
    21     case base::FILE_EXE:
    22     case base::FILE_MODULE: { // TODO(evanm): is this correct?
    23       char bin_dir[PATH_MAX + 1];
    24       int bin_dir_size = readlink("/proc/self/exe", bin_dir, PATH_MAX);
    25       if (bin_dir_size < 0 || bin_dir_size > PATH_MAX) {
    26         NOTREACHED() << "Unable to resolve /proc/self/exe.";
    27         return false;
    28       }
    29       bin_dir[bin_dir_size] = 0;
    30       *result = FilePath(bin_dir);
    31       return true;
    32     }
    33     case base::DIR_SOURCE_ROOT:
    34       // On linux, unit tests execute two levels deep from the source root.
    35       // For example:  sconsbuild/{Debug|Release}/net_unittest
    36       if (!PathService::Get(base::DIR_EXE, &path))
    37         return false;
    38       path = path.Append(FilePath::kParentDirectory)
    39                  .Append(FilePath::kParentDirectory);
    40       *result = path;
    41       return true;
    42   }
    43   return false;
    44 }
    46 }  // namespace base

mercurial