1 // Copyright (c) 2106 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_WINDOWS_IS_RUNNING_HPP
7 #define BOOST_PROCESS_WINDOWS_IS_RUNNING_HPP
8 
9 #include <boost/process/detail/config.hpp>
10 #include <system_error>
11 #include <cstdlib>
12 #include <boost/winapi/process.hpp>
13 
14 namespace boost { namespace process { namespace detail { namespace windows {
15 
16 constexpr static ::boost::winapi::DWORD_ still_active = 259;
17 
18 
19 struct child_handle;
20 
is_running(const child_handle & p,int & exit_code,std::error_code & ec)21 inline bool is_running(const child_handle &p, int & exit_code, std::error_code &ec) noexcept
22 {
23     ::boost::winapi::DWORD_ code;
24     //single value, not needed in the winapi.
25     if (!::boost::winapi::GetExitCodeProcess(p.process_handle(), &code))
26         ec = ::boost::process::detail::get_last_error();
27     else
28         ec.clear();
29 
30     if (code == still_active)
31         return true;
32     else
33     {
34         exit_code = code;
35         return false;
36     }
37 }
38 
is_running(const child_handle & p,int & exit_code)39 inline bool is_running(const child_handle &p, int & exit_code)
40 {
41     std::error_code ec;
42     bool b = is_running(p, exit_code, ec);
43     boost::process::detail::throw_error(ec, "GetExitCodeProcess() failed in is_running");
44     return b;
45 }
46 
is_running(int code)47 inline bool is_running(int code)
48 {
49     return code == still_active;
50 }
51 
eval_exit_status(int in)52 inline int eval_exit_status(int in ) {return in;}
53 
54 }}}}
55 
56 #endif
57