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 // Copyright (c) 2016 Klemens D. Morgenstern
0007 //
0008 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0009 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0010 
0011 #ifndef BOOST_PROCESS_POSIX_PIPE_OUT_HPP
0012 #define BOOST_PROCESS_POSIX_PIPE_OUT_HPP
0013 
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 <unistd.h>
0018 #include <array>
0019 
0020 namespace boost { namespace process { namespace detail { namespace posix {
0021 
0022 template<int p1, int p2>
0023 struct null_out : handler_base_ext, ::boost::process::detail::uses_handles
0024 {
0025     file_descriptor sink{"/dev/null", file_descriptor::write};
0026     
0027     template <typename Executor>
0028     void on_exec_setup(Executor &e) const;
0029 
0030     std::array<int, 3> get_used_handles()
0031     {
0032         const auto pp1 = p1 != -1 ? p1 : p2;
0033         const auto pp2 = p2 != -1 ? p2 : p1;
0034 
0035         return {sink.handle(), pp1, pp2};
0036     }
0037 };
0038 
0039 template<>
0040 template<typename Executor>
0041 void null_out<1,-1>::on_exec_setup(Executor &e) const
0042 {
0043     if (::dup2(sink.handle(), STDOUT_FILENO) == -1)
0044          e.set_error(::boost::process::detail::get_last_error(), "dup2() failed");
0045 }
0046 
0047 template<>
0048 template<typename Executor>
0049 void null_out<2,-1>::on_exec_setup(Executor &e) const
0050 {
0051     if (::dup2(sink.handle(), STDERR_FILENO) == -1)
0052          e.set_error(::boost::process::detail::get_last_error(), "dup2() failed");
0053 }
0054 
0055 template<>
0056 template<typename Executor>
0057 void null_out<1,2>::on_exec_setup(Executor &e) const
0058 {
0059     if (::dup2(sink.handle(), STDOUT_FILENO) == -1)
0060          e.set_error(::boost::process::detail::get_last_error(), "dup2() failed");
0061 
0062     if (::dup2(sink.handle(), STDERR_FILENO) == -1)
0063          e.set_error(::boost::process::detail::get_last_error(), "dup2() failed");
0064 }
0065 
0066 }}}}
0067 
0068 #endif