2 // Copyright (c) 2015-2016 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_WIN32_HPP
11 #define BOOST_BEAST_CORE_FILE_WIN32_HPP
13 #include <boost/config.hpp>
15 #if ! defined(BOOST_BEAST_USE_WIN32_FILE)
17 # define BOOST_BEAST_USE_WIN32_FILE 1
19 # define BOOST_BEAST_USE_WIN32_FILE 0
23 #if BOOST_BEAST_USE_WIN32_FILE
25 #include <boost/beast/core/error.hpp>
26 #include <boost/beast/core/file_base.hpp>
27 #include <boost/winapi/basic_types.hpp>
28 #include <boost/winapi/handles.hpp>
35 /** An implementation of File for Win32.
37 This class implements a @b File using Win32 native interfaces.
41 boost::winapi::HANDLE_ h_ =
42 boost::winapi::INVALID_HANDLE_VALUE_;
45 /** The type of the underlying file handle.
47 This is platform-specific.
49 #if BOOST_BEAST_DOXYGEN
50 using native_handle_type = HANDLE;
52 using native_handle_type = boost::winapi::HANDLE_;
57 If the file is open it is first closed.
63 There is no open file initially.
65 file_win32() = default;
69 The moved-from object behaves as if default constructed.
71 file_win32(file_win32&& other);
75 The moved-from object behaves as if default constructed.
77 file_win32& operator=(file_win32&& other);
79 /// Returns the native handle associated with the file.
86 /** Set the native handle associated with the file.
88 If the file is open it is first closed.
90 @param h The native file handle to assign.
93 native_handle(native_handle_type h);
95 /// Returns `true` if the file is open
99 return h_ != boost::winapi::INVALID_HANDLE_VALUE_;
102 /** Close the file if open
104 @param ec Set to the error, if any occurred.
107 close(error_code& ec);
109 /** Open a file at the given path with the specified mode
111 @param path The utf-8 encoded path to the file
113 @param mode The file mode to use
115 @param ec Set to the error, if any occurred
118 open(char const* path, file_mode mode, error_code& ec);
120 /** Return the size of the open file
122 @param ec Set to the error, if any occurred
124 @return The size in bytes
127 size(error_code& ec) const;
129 /** Return the current position in the open file
131 @param ec Set to the error, if any occurred
133 @return The offset in bytes from the beginning of the file
138 /** Adjust the current position in the open file
140 @param offset The offset in bytes from the beginning of the file
142 @param ec Set to the error, if any occurred
145 seek(std::uint64_t offset, error_code& ec);
147 /** Read from the open file
149 @param buffer The buffer for storing the result of the read
151 @param n The number of bytes to read
153 @param ec Set to the error, if any occurred
156 read(void* buffer, std::size_t n, error_code& ec);
158 /** Write to the open file
160 @param buffer The buffer holding the data to write
162 @param n The number of bytes to write
164 @param ec Set to the error, if any occurred
167 write(void const* buffer, std::size_t n, error_code& ec);
173 #include <boost/beast/core/impl/file_win32.ipp>