File indexing completed on 2025-01-18 09:50:06
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_PROCESS_POSIX_FILE_OUT_HPP
0012 #define BOOST_PROCESS_POSIX_FILE_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
0019 namespace boost { namespace process { namespace detail { namespace posix {
0020
0021 template<int p1, int p2>
0022 struct file_out : handler_base_ext, ::boost::process::detail::uses_handles
0023 {
0024 file_descriptor file;
0025 int handle = file.handle();
0026
0027 template<typename T>
0028 file_out(T&& t) : file(std::forward<T>(t), file_descriptor::write), handle(file.handle()) {}
0029 file_out(FILE * f) : handle(fileno(f)) {}
0030
0031 std::array<int, 3> get_used_handles()
0032 {
0033 const auto pp1 = p1 != -1 ? p1 : p2;
0034 const auto pp2 = p2 != -1 ? p2 : p1;
0035
0036 return {handle, pp1, pp2};
0037 }
0038
0039 template <typename Executor>
0040 void on_exec_setup(Executor &e) const;
0041 };
0042
0043 template<>
0044 template<typename Executor>
0045 void file_out<1,-1>::on_exec_setup(Executor &e) const
0046 {
0047 if (::dup2(handle, STDOUT_FILENO) == -1)
0048 e.set_error(::boost::process::detail::get_last_error(), "dup2() failed");
0049 }
0050
0051 template<>
0052 template<typename Executor>
0053 void file_out<2,-1>::on_exec_setup(Executor &e) const
0054 {
0055 if (::dup2(handle, STDERR_FILENO) == -1)
0056 e.set_error(::boost::process::detail::get_last_error(), "dup2() failed");
0057 }
0058
0059 template<>
0060 template<typename Executor>
0061 void file_out<1,2>::on_exec_setup(Executor &e) const
0062 {
0063 if (::dup2(handle, STDOUT_FILENO) == -1)
0064 e.set_error(::boost::process::detail::get_last_error(), "dup2() failed");
0065
0066 if (::dup2(handle, STDERR_FILENO) == -1)
0067 e.set_error(::boost::process::detail::get_last_error(), "dup2() failed");
0068
0069 }
0070
0071 }}}}
0072
0073 #endif