Back to home page

EIC code displayed by LXR

 
 

    


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

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_POSIX_FILE_IN_HPP
0011 #define BOOST_PROCESS_DETAIL_POSIX_FILE_IN_HPP
0012 
0013 #include <boost/process/pipe.hpp>
0014 #include <boost/process/detail/posix/handler.hpp>
0015 #include <boost/process/detail/posix/file_descriptor.hpp>
0016 #include <boost/process/detail/used_handles.hpp>
0017 #include <cstdio>
0018 #include <unistd.h>
0019 
0020 namespace boost { namespace process { namespace detail { namespace posix {
0021 
0022 struct file_in : handler_base_ext, ::boost::process::detail::uses_handles
0023 {
0024     file_descriptor file;
0025     int handle = file.handle();
0026 
0027     std::array<int, 2> get_used_handles()
0028     {
0029         return {{STDIN_FILENO, handle}};
0030     }
0031 
0032     template<typename T>
0033     file_in(T&& t) : file(std::forward<T>(t)) {}
0034     file_in(FILE * f) : handle(fileno(f)) {}
0035 
0036     template <class WindowsExecutor>
0037     void on_exec_setup(WindowsExecutor &e) const
0038     {
0039         if (::dup2(handle, STDIN_FILENO) == -1)
0040              e.set_error(::boost::process::detail::get_last_error(), "dup2() failed");
0041     }
0042 };
0043 
0044 }}}}
0045 
0046 #endif