Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
static const uint8_t buffer[]
#define FML_CHECK(condition)
Definition logging.h:85
std::string AbsolutePath(const std::string &path)
std::string SanitizeURIEscapedCharacters(const std::string &str)
Definition paths.cc:32
std::string GetDirectoryName(const std::string &path)
std::string FromURI(const std::string &uri)
#define PATH_MAX
Definition globals.h:708
#define GetCurrentDirectory