summaryrefslogtreecommitdiff
path: root/boost/process/detail/windows/file_descriptor.hpp
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2017-09-13 11:08:07 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2017-09-13 11:09:00 +0900
commitb5c87084afaef42b2d058f68091be31988a6a874 (patch)
treeadef9a65870a41181687e11d57fdf98e7629de3c /boost/process/detail/windows/file_descriptor.hpp
parent34bd32e225e2a8a94104489b31c42e5801cc1f4a (diff)
downloadboost-b5c87084afaef42b2d058f68091be31988a6a874.tar.gz
boost-b5c87084afaef42b2d058f68091be31988a6a874.tar.bz2
boost-b5c87084afaef42b2d058f68091be31988a6a874.zip
Imported Upstream version 1.64.0upstream/1.64.0
Change-Id: Id9212edd016dd55f21172c427aa7894d1d24148b Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'boost/process/detail/windows/file_descriptor.hpp')
-rw-r--r--boost/process/detail/windows/file_descriptor.hpp104
1 files changed, 104 insertions, 0 deletions
diff --git a/boost/process/detail/windows/file_descriptor.hpp b/boost/process/detail/windows/file_descriptor.hpp
new file mode 100644
index 0000000000..337e634781
--- /dev/null
+++ b/boost/process/detail/windows/file_descriptor.hpp
@@ -0,0 +1,104 @@
+// Copyright (c) 2016 Klemens D. Morgenstern
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_PROCESS_DETAIL_WINDOWS_FILE_DESCRIPTOR_HPP_
+#define BOOST_PROCESS_DETAIL_WINDOWS_FILE_DESCRIPTOR_HPP_
+
+#include <boost/detail/winapi/basic_types.hpp>
+#include <boost/detail/winapi/handles.hpp>
+#include <boost/detail/winapi/file_management.hpp>
+#include <string>
+#include <boost/filesystem/path.hpp>
+
+namespace boost { namespace process { namespace detail { namespace windows {
+
+struct file_descriptor
+{
+ enum mode_t
+ {
+ read = 1,
+ write = 2,
+ read_write = 3
+ };
+ static ::boost::detail::winapi::DWORD_ desired_access(mode_t mode)
+ {
+ switch(mode)
+ {
+ case read:
+ return ::boost::detail::winapi::GENERIC_READ_;
+ case write:
+ return ::boost::detail::winapi::GENERIC_WRITE_;
+ case read_write:
+ return ::boost::detail::winapi::GENERIC_READ_
+ | ::boost::detail::winapi::GENERIC_WRITE_;
+ default:
+ return 0u;
+ }
+ }
+
+ file_descriptor() = default;
+ file_descriptor(const boost::filesystem::path& p, mode_t mode = read_write)
+ : file_descriptor(p.native(), mode)
+ {
+ }
+
+ file_descriptor(const std::string & path , mode_t mode = read_write)
+ : file_descriptor(path.c_str(), mode) {}
+ file_descriptor(const std::wstring & path, mode_t mode = read_write)
+ : file_descriptor(path.c_str(), mode) {}
+
+ file_descriptor(const char* path, mode_t mode = read_write)
+ : _handle(
+ ::boost::detail::winapi::create_file(
+ path,
+ desired_access(mode),
+ ::boost::detail::winapi::FILE_SHARE_READ_ |
+ ::boost::detail::winapi::FILE_SHARE_WRITE_,
+ nullptr,
+ ::boost::detail::winapi::OPEN_ALWAYS_,
+
+ ::boost::detail::winapi::FILE_ATTRIBUTE_NORMAL_,
+ nullptr
+ ))
+ {
+
+ }
+ file_descriptor(const wchar_t * path, mode_t mode = read_write)
+ : _handle(
+ ::boost::detail::winapi::create_file(
+ path,
+ desired_access(mode),
+ ::boost::detail::winapi::FILE_SHARE_READ_ |
+ ::boost::detail::winapi::FILE_SHARE_WRITE_,
+ nullptr,
+ ::boost::detail::winapi::OPEN_ALWAYS_,
+
+ ::boost::detail::winapi::FILE_ATTRIBUTE_NORMAL_,
+ nullptr
+ ))
+{
+
+}
+ file_descriptor(const file_descriptor & ) = delete;
+ file_descriptor(file_descriptor && ) = default;
+
+ file_descriptor& operator=(const file_descriptor & ) = delete;
+ file_descriptor& operator=(file_descriptor && ) = default;
+
+ ~file_descriptor()
+ {
+ if (_handle != ::boost::detail::winapi::INVALID_HANDLE_VALUE_)
+ ::boost::detail::winapi::CloseHandle(_handle);
+ }
+
+ ::boost::detail::winapi::HANDLE_ handle() const { return _handle;}
+
+private:
+ ::boost::detail::winapi::HANDLE_ _handle = ::boost::detail::winapi::INVALID_HANDLE_VALUE_;
+};
+
+}}}}
+
+#endif /* BOOST_PROCESS_DETAIL_WINDOWS_FILE_DESCRIPTOR_HPP_ */