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_POSIX_COMPARE_HANDLES_HPP_
7 #define BOOST_PROCESS_DETAIL_POSIX_COMPARE_HANDLES_HPP_
8 
9 
10 #include <boost/process/detail/config.hpp>
11 #include <sys/types.h>
12 #include <sys/stat.h>
13 #include <unistd.h>
14 
15 namespace boost { namespace process { namespace detail { namespace posix {
16 
17 
compare_handles(int lhs,int rhs)18 inline bool compare_handles(int lhs, int rhs)
19 {
20 
21     if ((lhs == -1) || (rhs == -1))
22         return false;
23 
24     if (lhs == rhs)
25         return true;
26 
27     struct stat stat1, stat2;
28     if(fstat(lhs, &stat1) < 0) ::boost::process::detail::throw_last_error("fstat() failed");
29     if(fstat(rhs, &stat2) < 0) ::boost::process::detail::throw_last_error("fstat() failed");
30 
31     return (stat1.st_dev == stat2.st_dev) && (stat1.st_ino == stat2.st_ino);
32 }
33 
34 
35 
36 
37 
38 }}}}
39 
40 
41 
42 #endif /* BOOST_PROCESS_DETAIL_POSIX_COMPARE_HANDLES_HPP_ */
43