compare_handles.hpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. #ifndef BOOST_PROCESS_DETAIL_WINDOWS_COMPARE_HANDLES_HPP_
  6. #define BOOST_PROCESS_DETAIL_WINDOWS_COMPARE_HANDLES_HPP_
  7. #include <boost/winapi/handles.hpp>
  8. #include <boost/winapi/file_management.hpp>
  9. #include <boost/process/detail/config.hpp>
  10. namespace boost { namespace process { namespace detail { namespace windows {
  11. inline bool compare_handles(boost::winapi::HANDLE_ lhs, boost::winapi::HANDLE_ rhs)
  12. {
  13. if ( (lhs == ::boost::winapi::INVALID_HANDLE_VALUE_)
  14. || (rhs == ::boost::winapi::INVALID_HANDLE_VALUE_))
  15. return false;
  16. if (lhs == rhs)
  17. return true;
  18. ::boost::winapi::BY_HANDLE_FILE_INFORMATION_ lhs_info{0,{0,0},{0,0},{0,0},0,0,0,0,0,0};
  19. ::boost::winapi::BY_HANDLE_FILE_INFORMATION_ rhs_info{0,{0,0},{0,0},{0,0},0,0,0,0,0,0};
  20. if (!::boost::winapi::GetFileInformationByHandle(lhs, &lhs_info))
  21. ::boost::process::detail::throw_last_error("GetFileInformationByHandle");
  22. if (!::boost::winapi::GetFileInformationByHandle(rhs, &rhs_info))
  23. ::boost::process::detail::throw_last_error("GetFileInformationByHandle");
  24. return (lhs_info.nFileIndexHigh == rhs_info.nFileIndexHigh)
  25. && (lhs_info.nFileIndexLow == rhs_info.nFileIndexLow);
  26. }
  27. }}}}
  28. #endif /* BOOST_PROCESS_DETAIL_WINDOWS_COMPARE_HANDLES_HPP_ */