Imported Upstream version 1.64.0
[platform/upstream/boost.git] / boost / process / detail / windows / terminate.hpp
1 // Copyright (c) 2006, 2007 Julio M. Merino Vidal
2 // Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
3 // Copyright (c) 2009 Boris Schaeling
4 // Copyright (c) 2010 Felipe Tanus, Boris Schaeling
5 // Copyright (c) 2011, 2012 Jeff Flinn, Boris Schaeling
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9
10 #ifndef BOOST_PROCESS_WINDOWS_TERMINATE_HPP
11 #define BOOST_PROCESS_WINDOWS_TERMINATE_HPP
12
13 #include <boost/process/detail/config.hpp>
14 #include <system_error>
15 #include <cstdlib>
16 #include <boost/detail/winapi/process.hpp>
17 #include <boost/detail/winapi/get_last_error.hpp>
18
19 namespace boost { namespace process { namespace detail { namespace windows {
20
21 struct child_handle;
22
23 inline void terminate(child_handle &p)
24 {
25     if (!::boost::detail::winapi::TerminateProcess(p.process_handle(), EXIT_FAILURE))
26         boost::process::detail::throw_last_error("TerminateProcess() failed");
27
28     ::boost::detail::winapi::CloseHandle(p.proc_info.hProcess);
29     p.proc_info.hProcess = ::boost::detail::winapi::INVALID_HANDLE_VALUE_;
30 }
31
32 inline void terminate(child_handle &p, std::error_code &ec) noexcept
33 {
34     if (!::boost::detail::winapi::TerminateProcess(p.process_handle(), EXIT_FAILURE))
35         ec = boost::process::detail::get_last_error();
36     else
37     {
38         ec.clear();
39         ::boost::detail::winapi::CloseHandle(p.proc_info.hProcess);
40         p.proc_info.hProcess = ::boost::detail::winapi::INVALID_HANDLE_VALUE_;
41     }
42 }
43
44
45
46
47 }}}}
48
49 #endif