ipc/chromium/src/base/base_paths_linux.cc

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ipc/chromium/src/base/base_paths_linux.cc	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,46 @@
     1.4 +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
     1.5 +// Use of this source code is governed by a BSD-style license that can be
     1.6 +// found in the LICENSE file.
     1.7 +
     1.8 +#include "base/base_paths_linux.h"
     1.9 +
    1.10 +#include <unistd.h>
    1.11 +
    1.12 +#include "base/file_path.h"
    1.13 +#include "base/file_util.h"
    1.14 +#include "base/logging.h"
    1.15 +#include "base/path_service.h"
    1.16 +#include "base/string_piece.h"
    1.17 +#include "base/sys_string_conversions.h"
    1.18 +
    1.19 +namespace base {
    1.20 +
    1.21 +bool PathProviderLinux(int key, FilePath* result) {
    1.22 +  FilePath path;
    1.23 +  switch (key) {
    1.24 +    case base::FILE_EXE:
    1.25 +    case base::FILE_MODULE: { // TODO(evanm): is this correct?
    1.26 +      char bin_dir[PATH_MAX + 1];
    1.27 +      int bin_dir_size = readlink("/proc/self/exe", bin_dir, PATH_MAX);
    1.28 +      if (bin_dir_size < 0 || bin_dir_size > PATH_MAX) {
    1.29 +        NOTREACHED() << "Unable to resolve /proc/self/exe.";
    1.30 +        return false;
    1.31 +      }
    1.32 +      bin_dir[bin_dir_size] = 0;
    1.33 +      *result = FilePath(bin_dir);
    1.34 +      return true;
    1.35 +    }
    1.36 +    case base::DIR_SOURCE_ROOT:
    1.37 +      // On linux, unit tests execute two levels deep from the source root.
    1.38 +      // For example:  sconsbuild/{Debug|Release}/net_unittest
    1.39 +      if (!PathService::Get(base::DIR_EXE, &path))
    1.40 +        return false;
    1.41 +      path = path.Append(FilePath::kParentDirectory)
    1.42 +                 .Append(FilePath::kParentDirectory);
    1.43 +      *result = path;
    1.44 +      return true;
    1.45 +  }
    1.46 +  return false;
    1.47 +}
    1.48 +
    1.49 +}  // namespace base

mercurial