Flutter Engine
The Flutter Engine
file.h
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#ifndef FILESYSTEM_FILE_H_
6#define FILESYSTEM_FILE_H_
7
8#include <string>
9#include <vector>
10
13
14namespace filesystem {
15
17 public:
18 using Handle = int;
19
20 Descriptor(Handle handle) : handle_(handle) {}
21
23 if (is_valid()) {
24 IGNORE_EINTR(::close(handle_));
25 }
26 }
27
28 bool is_valid() { return handle_ >= 0; }
29
30 Handle get() { return handle_; }
31
32 private:
33 Handle handle_ = -1;
34
35 Descriptor(Descriptor&) = delete;
36
37 void operator=(const Descriptor&) = delete;
38};
39
40// Reads the contents of the file at the given path or file descriptor and
41// stores the data in result. Returns true if the file was read successfully,
42// otherwise returns false. If this function returns false, |result| will be
43// the empty string.
44bool ReadFileToString(const std::string& path, std::string* result);
45bool ReadFileDescriptorToString(int fd, std::string* result);
46
47// Reads the contents of the file at the given path and if successful, returns
48// pair of read allocated bytes with data and size of the data if successful.
49// pair of <nullptr, -1> if read failed.
50std::pair<uint8_t*, intptr_t> ReadFileToBytes(const std::string& path);
51std::pair<uint8_t*, intptr_t> ReadFileDescriptorToBytes(int fd);
52
53} // namespace filesystem
54
55#endif // FILESYSTEM_FILE_H_
Handle get()
Definition: file.h:30
Descriptor(Handle handle)
Definition: file.h:20
GAsyncResult * result
bool ReadFileDescriptorToString(int fd, std::string *result)
Definition: file.cc:90
bool ReadFileToString(const std::string &path, std::string *result)
Definition: file.cc:85
std::pair< uint8_t *, intptr_t > ReadFileToBytes(const std::string &path)
Definition: file.cc:94
std::pair< uint8_t *, intptr_t > ReadFileDescriptorToBytes(int fd)
Definition: file.cc:63
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
#define IGNORE_EINTR(x)
Definition: eintr_wrapper.h:46