Flutter Engine
The Flutter Engine
paths_posix.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter 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 "flutter/fml/paths.h"
6
7#include <unistd.h>
8
9#include <climits>
10
11#include "flutter/fml/logging.h"
12
13namespace fml {
14namespace paths {
15
16namespace {
17
18constexpr char kFileURLPrefix[] = "file://";
19constexpr size_t kFileURLPrefixLength = sizeof(kFileURLPrefix) - 1;
20
21std::string GetCurrentDirectory() {
22 char buffer[PATH_MAX];
23 FML_CHECK(getcwd(buffer, sizeof(buffer)));
24 return std::string(buffer);
25}
26
27} // namespace
28
29std::string AbsolutePath(const std::string& path) {
30 if (!path.empty()) {
31 if (path[0] == '/') {
32 // Path is already absolute.
33 return path;
34 }
35 return GetCurrentDirectory() + "/" + path;
36 } else {
37 // Path is empty.
38 return GetCurrentDirectory();
39 }
40}
41
42std::string GetDirectoryName(const std::string& path) {
43 size_t separator = path.rfind('/');
44 if (separator == 0u) {
45 return "/";
46 }
47 if (separator == std::string::npos) {
48 return std::string();
49 }
50 return path.substr(0, separator);
51}
52
53std::string FromURI(const std::string& uri) {
54 if (uri.substr(0, kFileURLPrefixLength) != kFileURLPrefix) {
55 return uri;
56 }
57
58 std::string file_path = uri.substr(kFileURLPrefixLength);
59 return SanitizeURIEscapedCharacters(file_path);
60}
61
62} // namespace paths
63} // namespace fml
#define FML_CHECK(condition)
Definition: logging.h:85
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
std::string AbsolutePath(const std::string &path)
Definition: paths_posix.cc:29
std::string SanitizeURIEscapedCharacters(const std::string &str)
Definition: paths.cc:32
std::string GetDirectoryName(const std::string &path)
Definition: paths_posix.cc:42
std::string FromURI(const std::string &uri)
Definition: paths_posix.cc:53
Definition: ascii_trie.cc:9
#define PATH_MAX
Definition: globals.h:708
#define GetCurrentDirectory