1 // Copyright (c) 2016 Klemens D. Morgenstern
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #ifndef BOOST_PROCESS_DETAIL_WINDOWS_FILE_DESCRIPTOR_HPP_
7 #define BOOST_PROCESS_DETAIL_WINDOWS_FILE_DESCRIPTOR_HPP_
9 #include <boost/winapi/basic_types.hpp>
10 #include <boost/winapi/handles.hpp>
11 #include <boost/winapi/file_management.hpp>
13 #include <boost/filesystem/path.hpp>
15 namespace boost { namespace process { namespace detail { namespace windows {
17 struct file_descriptor
25 static ::boost::winapi::DWORD_ desired_access(mode_t mode)
30 return ::boost::winapi::GENERIC_READ_;
32 return ::boost::winapi::GENERIC_WRITE_;
34 return ::boost::winapi::GENERIC_READ_
35 | ::boost::winapi::GENERIC_WRITE_;
41 file_descriptor() = default;
42 file_descriptor(const boost::filesystem::path& p, mode_t mode = read_write)
43 : file_descriptor(p.native(), mode)
47 file_descriptor(const std::string & path , mode_t mode = read_write)
48 : file_descriptor(path.c_str(), mode) {}
49 file_descriptor(const std::wstring & path, mode_t mode = read_write)
50 : file_descriptor(path.c_str(), mode) {}
52 file_descriptor(const char* path, mode_t mode = read_write)
54 ::boost::winapi::create_file(
57 ::boost::winapi::FILE_SHARE_READ_ |
58 ::boost::winapi::FILE_SHARE_WRITE_,
60 ::boost::winapi::OPEN_ALWAYS_,
62 ::boost::winapi::FILE_ATTRIBUTE_NORMAL_,
68 file_descriptor(const wchar_t * path, mode_t mode = read_write)
70 ::boost::winapi::create_file(
73 ::boost::winapi::FILE_SHARE_READ_ |
74 ::boost::winapi::FILE_SHARE_WRITE_,
76 ::boost::winapi::OPEN_ALWAYS_,
78 ::boost::winapi::FILE_ATTRIBUTE_NORMAL_,
84 file_descriptor(const file_descriptor & ) = delete;
85 file_descriptor(file_descriptor && ) = default;
87 file_descriptor& operator=(const file_descriptor & ) = delete;
88 file_descriptor& operator=(file_descriptor && ) = default;
92 if (_handle != ::boost::winapi::INVALID_HANDLE_VALUE_)
93 ::boost::winapi::CloseHandle(_handle);
96 ::boost::winapi::HANDLE_ handle() const { return _handle;}
99 ::boost::winapi::HANDLE_ _handle = ::boost::winapi::INVALID_HANDLE_VALUE_;
104 #endif /* BOOST_PROCESS_DETAIL_WINDOWS_FILE_DESCRIPTOR_HPP_ */