blob: 41883d9032c188ecd42d785d6d32235dff212e8f [file] [log] [blame]
scottmg1ab7aa82017-05-25 05:22:491// Copyright 2017 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.
4
5#include "base/base_paths.h"
6
Kevin Marshallfe2f08c2017-08-25 21:45:297#include <stdlib.h>
8
9#include "base/command_line.h"
John Budorick7f8f2052018-01-25 17:48:4410#include "base/files/file_path.h"
scottmg1ab7aa82017-05-25 05:22:4911
12namespace base {
13
14bool PathProviderFuchsia(int key, FilePath* result) {
15 switch (key) {
Scott Graham4bd2b07f2017-06-01 04:17:0416 case FILE_MODULE:
John Budorick7f8f2052018-01-25 17:48:4417 // Not supported in debug or component builds. Fall back on using the EXE
18 // path for now.
19 // TODO(fuchsia): Get this value from an API. See crbug.com/726124
Kevin Marshallfe2f08c2017-08-25 21:45:2920 case FILE_EXE: {
John Budorick7f8f2052018-01-25 17:48:4421 // Use the binary name as specified on the command line.
22 // TODO(fuchsia): It would be nice to get the canonical executable path
23 // from a kernel API. See https://crbug.com/726124
24 char bin_dir[PATH_MAX + 1];
25 if (realpath(base::CommandLine::ForCurrentProcess()
26 ->GetProgram()
27 .AsUTF8Unsafe()
28 .c_str(),
29 bin_dir) == NULL) {
30 return false;
31 }
32 *result = FilePath(bin_dir);
Scott Graham4bd2b07f2017-06-01 04:17:0433 return true;
Kevin Marshallfe2f08c2017-08-25 21:45:2934 }
Scott Graham4bd2b07f2017-06-01 04:17:0435 case DIR_SOURCE_ROOT:
John Budorick7f8f2052018-01-25 17:48:4436 // This is only used for tests, so we return the binary location for now.
37 *result = FilePath("/system");
Scott Graham4bd2b07f2017-06-01 04:17:0438 return true;
39 case DIR_CACHE:
40 *result = FilePath("/data");
41 return true;
scottmg1ab7aa82017-05-25 05:22:4942 }
John Budorick7f8f2052018-01-25 17:48:4443
scottmg1ab7aa82017-05-25 05:22:4944 return false;
45}
46
47} // namespace base