Imported Upstream version 1.64.0
[platform/upstream/boost.git] / boost / process / detail / windows / compare_handles.hpp
1 // Copyright (c) 2016 Klemens D. Morgenstern
2 //
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)
5
6 #ifndef BOOST_PROCESS_DETAIL_WINDOWS_COMPARE_HANDLES_HPP_
7 #define BOOST_PROCESS_DETAIL_WINDOWS_COMPARE_HANDLES_HPP_
8
9 #include <boost/detail/winapi/handles.hpp>
10 #include <boost/detail/winapi/file_management.hpp>
11 #include <boost/process/detail/config.hpp>
12
13 namespace boost { namespace process { namespace detail { namespace windows {
14
15 inline bool compare_handles(boost::detail::winapi::HANDLE_ lhs, boost::detail::winapi::HANDLE_ rhs)
16 {
17     if ( (lhs == ::boost::detail::winapi::INVALID_HANDLE_VALUE_)
18       || (rhs == ::boost::detail::winapi::INVALID_HANDLE_VALUE_))
19         return false;
20
21     if (lhs == rhs)
22         return true;
23
24     ::boost::detail::winapi::BY_HANDLE_FILE_INFORMATION_ lhs_info{0,{0,0},{0,0},{0,0},0,0,0,0,0,0};
25     ::boost::detail::winapi::BY_HANDLE_FILE_INFORMATION_ rhs_info{0,{0,0},{0,0},{0,0},0,0,0,0,0,0};
26
27     if (!::boost::detail::winapi::GetFileInformationByHandle(lhs, &lhs_info))
28         ::boost::process::detail::throw_last_error("GetFileInformationByHandle");
29
30     if (!::boost::detail::winapi::GetFileInformationByHandle(rhs, &rhs_info))
31         ::boost::process::detail::throw_last_error("GetFileInformationByHandle");
32
33     return     (lhs_info.nFileIndexHigh == rhs_info.nFileIndexHigh)
34             && (lhs_info.nFileIndexLow  == rhs_info.nFileIndexLow);
35 }
36
37 }}}}
38
39
40
41 #endif /* BOOST_PROCESS_DETAIL_WINDOWS_COMPARE_HANDLES_HPP_ */