Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:50:08

0001 // Copyright (c) 2006, 2007 Julio M. Merino Vidal
0002 // Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
0003 // Copyright (c) 2009 Boris Schaeling
0004 // Copyright (c) 2010 Felipe Tanus, Boris Schaeling
0005 // Copyright (c) 2011, 2012 Jeff Flinn, Boris Schaeling
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 
0010 #ifndef BOOST_PROCESS_DETAIL_WINDOWS_FILE_OUT_HPP
0011 #define BOOST_PROCESS_DETAIL_WINDOWS_FILE_OUT_HPP
0012 
0013 #include <boost/winapi/process.hpp>
0014 #include <boost/winapi/handles.hpp>
0015 #include <boost/winapi/handle_info.hpp>
0016 #include <boost/process/detail/handler_base.hpp>
0017 #include <boost/process/detail/used_handles.hpp>
0018 #include <boost/process/detail/windows/file_descriptor.hpp>
0019 
0020 namespace boost { namespace process { namespace detail { namespace windows {
0021 
0022 template<int p1, int p2>
0023 struct file_out : public ::boost::process::detail::handler_base,
0024                          ::boost::process::detail::uses_handles
0025 {
0026     file_descriptor file;
0027     ::boost::winapi::HANDLE_ handle = file.handle();
0028 
0029     ::boost::winapi::HANDLE_ get_used_handles() const { return handle; }
0030 
0031 
0032     template<typename T>
0033     file_out(T&& t) : file(std::forward<T>(t), file_descriptor::write) {}
0034     file_out(FILE * f) : handle(reinterpret_cast<void*>(_get_osfhandle(_fileno(f)))) {}
0035 
0036     template <typename WindowsExecutor>
0037     inline void on_setup(WindowsExecutor &e) const;
0038 };
0039 
0040 template<>
0041 template<typename WindowsExecutor>
0042 void file_out<1,-1>::on_setup(WindowsExecutor &e) const
0043 {
0044     boost::winapi::SetHandleInformation(handle,
0045             boost::winapi::HANDLE_FLAG_INHERIT_,
0046             boost::winapi::HANDLE_FLAG_INHERIT_);
0047 
0048     e.startup_info.hStdOutput = handle;
0049     e.startup_info.dwFlags   |= ::boost::winapi::STARTF_USESTDHANDLES_;
0050     e.inherit_handles = true;
0051 }
0052 
0053 template<>
0054 template<typename WindowsExecutor>
0055 void file_out<2,-1>::on_setup(WindowsExecutor &e) const
0056 {
0057     boost::winapi::SetHandleInformation(handle,
0058             boost::winapi::HANDLE_FLAG_INHERIT_,
0059             boost::winapi::HANDLE_FLAG_INHERIT_);
0060 
0061     e.startup_info.hStdError = handle;
0062     e.startup_info.dwFlags  |= ::boost::winapi::STARTF_USESTDHANDLES_;
0063     e.inherit_handles = true;
0064 }
0065 
0066 template<>
0067 template<typename WindowsExecutor>
0068 void file_out<1,2>::on_setup(WindowsExecutor &e) const
0069 {
0070     boost::winapi::SetHandleInformation(handle,
0071             boost::winapi::HANDLE_FLAG_INHERIT_,
0072             boost::winapi::HANDLE_FLAG_INHERIT_);
0073 
0074     e.startup_info.hStdOutput = handle;
0075     e.startup_info.hStdError  = handle;
0076     e.startup_info.dwFlags   |= ::boost::winapi::STARTF_USESTDHANDLES_;
0077     e.inherit_handles = true;
0078 }
0079 
0080 }}}}
0081 
0082 #endif