2 // Copyright (c) 2015-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // Official repository: https://github.com/boostorg/beast
10 #ifndef BOOST_BEAST_CORE_FILE_STDIO_HPP
11 #define BOOST_BEAST_CORE_FILE_STDIO_HPP
13 #include <boost/beast/core/detail/config.hpp>
14 #include <boost/beast/core/error.hpp>
15 #include <boost/beast/core/file_base.hpp>
22 /** An implementation of File which uses cstdio.
24 This class implements a file using the interfaces present
25 in the C++ Standard Library, in `<stdio>`.
29 std::FILE* f_ = nullptr;
32 /** The type of the underlying file handle.
34 This is platform-specific.
36 using native_handle_type = std::FILE*;
40 If the file is open it is first closed.
47 There is no open file initially.
49 file_stdio() = default;
53 The moved-from object behaves as if default constructed.
56 file_stdio(file_stdio&& other);
60 The moved-from object behaves as if default constructed.
63 file_stdio& operator=(file_stdio&& other);
65 /// Returns the native handle associated with the file.
72 /** Set the native handle associated with the file.
74 If the file is open it is first closed.
76 @param f The native file handle to assign.
80 native_handle(std::FILE* f);
82 /// Returns `true` if the file is open
89 /** Close the file if open
91 @param ec Set to the error, if any occurred.
95 close(error_code& ec);
97 /** Open a file at the given path with the specified mode
99 @param path The utf-8 encoded path to the file
101 @param mode The file mode to use
103 @param ec Set to the error, if any occurred
107 open(char const* path, file_mode mode, error_code& ec);
109 /** Return the size of the open file
111 @param ec Set to the error, if any occurred
113 @return The size in bytes
117 size(error_code& ec) const;
119 /** Return the current position in the open file
121 @param ec Set to the error, if any occurred
123 @return The offset in bytes from the beginning of the file
127 pos(error_code& ec) const;
129 /** Adjust the current position in the open file
131 @param offset The offset in bytes from the beginning of the file
133 @param ec Set to the error, if any occurred
137 seek(std::uint64_t offset, error_code& ec);
139 /** Read from the open file
141 @param buffer The buffer for storing the result of the read
143 @param n The number of bytes to read
145 @param ec Set to the error, if any occurred
149 read(void* buffer, std::size_t n, error_code& ec) const;
151 /** Write to the open file
153 @param buffer The buffer holding the data to write
155 @param n The number of bytes to write
157 @param ec Set to the error, if any occurred
161 write(void const* buffer, std::size_t n, error_code& ec);
167 #ifdef BOOST_BEAST_HEADER_ONLY
168 #include <boost/beast/core/impl/file_stdio.ipp>