compare_handles.hpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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_POSIX_COMPARE_HANDLES_HPP_
  6. #define BOOST_PROCESS_DETAIL_POSIX_COMPARE_HANDLES_HPP_
  7. #include <boost/process/detail/config.hpp>
  8. #include <sys/types.h>
  9. #include <sys/stat.h>
  10. #include <unistd.h>
  11. namespace boost { namespace process { namespace detail { namespace posix {
  12. inline bool compare_handles(int lhs, int rhs)
  13. {
  14. if ((lhs == -1) || (rhs == -1))
  15. return false;
  16. if (lhs == rhs)
  17. return true;
  18. struct stat stat1, stat2;
  19. if(fstat(lhs, &stat1) < 0) ::boost::process::detail::throw_last_error("fstat() failed");
  20. if(fstat(rhs, &stat2) < 0) ::boost::process::detail::throw_last_error("fstat() failed");
  21. return (stat1.st_dev == stat2.st_dev) && (stat1.st_ino == stat2.st_ino);
  22. }
  23. }}}}
  24. #endif /* BOOST_PROCESS_DETAIL_POSIX_COMPARE_HANDLES_HPP_ */