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