Flutter Engine
 
Loading...
Searching...
No Matches
files.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 "files.h"
6
7#include <fcntl.h>
8#include <unistd.h>
9
10#include <cstdint>
11
12#include "flutter/fml/logging.h"
13
14namespace dart_utils {
15
16namespace {
17
18bool ReadFileDescriptor(int fd, std::string* result) {
19 FML_DCHECK(result);
20 result->clear();
21
22 if (fd < 0) {
23 return false;
24 }
25
26 constexpr size_t kBufferSize = 1 << 16;
27 size_t offset = 0;
28 ssize_t bytes_read = 0;
29 do {
30 offset += bytes_read;
31 result->resize(offset + kBufferSize);
32 bytes_read = read(fd, &(*result)[offset], kBufferSize);
33 } while (bytes_read > 0);
34
35 if (bytes_read < 0) {
36 result->clear();
37 return false;
38 }
39
40 result->resize(offset + bytes_read);
41 return true;
42}
43
44bool WriteFileDescriptor(int fd, const char* data, ssize_t size) {
45 ssize_t total = 0;
46 for (ssize_t partial = 0; total < size; total += partial) {
47 partial = write(fd, data + total, size - total);
48 if (partial < 0)
49 return false;
50 }
51 return true;
52}
53
54} // namespace
55
56bool ReadFileToString(const std::string& path, std::string* result) {
57 return ReadFileToStringAt(AT_FDCWD, path, result);
58}
59
60bool ReadFileToStringAt(int dirfd,
61 const std::string& path,
62 std::string* result) {
63 int fd = openat(dirfd, path.c_str(), O_RDONLY);
64 bool status = ReadFileDescriptor(fd, result);
65 close(fd);
66 return status;
67}
68
69bool WriteFile(const std::string& path, const char* data, ssize_t size) {
70 int fd = openat(AT_FDCWD, path.c_str(), O_CREAT | O_TRUNC | O_WRONLY, 0666);
71 if (fd < 0) {
72 return false;
73 }
74 bool status = WriteFileDescriptor(fd, data, size);
75 close(fd);
76 return status;
77}
78
79} // namespace dart_utils
#define FML_DCHECK(condition)
Definition logging.h:122
bool ReadFileToString(const std::string &path, std::string *result)
Definition files.cc:56
bool WriteFile(const std::string &path, const char *data, ssize_t size)
Definition files.cc:69
bool ReadFileToStringAt(int dirfd, const std::string &path, std::string *result)
Definition files.cc:60
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
std::shared_ptr< const fml::Mapping > data