michael@0: // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #include "base/base_paths_linux.h" michael@0: michael@0: #include michael@0: michael@0: #include "base/file_path.h" michael@0: #include "base/file_util.h" michael@0: #include "base/logging.h" michael@0: #include "base/path_service.h" michael@0: #include "base/string_piece.h" michael@0: #include "base/sys_string_conversions.h" michael@0: michael@0: namespace base { michael@0: michael@0: bool PathProviderLinux(int key, FilePath* result) { michael@0: FilePath path; michael@0: switch (key) { michael@0: case base::FILE_EXE: michael@0: case base::FILE_MODULE: { // TODO(evanm): is this correct? michael@0: char bin_dir[PATH_MAX + 1]; michael@0: int bin_dir_size = readlink("/proc/self/exe", bin_dir, PATH_MAX); michael@0: if (bin_dir_size < 0 || bin_dir_size > PATH_MAX) { michael@0: NOTREACHED() << "Unable to resolve /proc/self/exe."; michael@0: return false; michael@0: } michael@0: bin_dir[bin_dir_size] = 0; michael@0: *result = FilePath(bin_dir); michael@0: return true; michael@0: } michael@0: case base::DIR_SOURCE_ROOT: michael@0: // On linux, unit tests execute two levels deep from the source root. michael@0: // For example: sconsbuild/{Debug|Release}/net_unittest michael@0: if (!PathService::Get(base::DIR_EXE, &path)) michael@0: return false; michael@0: path = path.Append(FilePath::kParentDirectory) michael@0: .Append(FilePath::kParentDirectory); michael@0: *result = path; michael@0: return true; michael@0: } michael@0: return false; michael@0: } michael@0: michael@0: } // namespace base