diff --git a/io.cpp b/io.cpp index 5b7a6d0e..0629e988 100644 --- a/io.cpp +++ b/io.cpp @@ -166,6 +166,18 @@ fd::~fd () { } +//----------------------------------------------------------------------------- +fd +fd::dup (int _fd) +{ + auto res = ::dup (_fd); + if (res < 0) + errno_error::throw_code (); + + return fd (res); +} + + ////////////////////////////////////////////////////////////////////////////// int indenter::overflow (int ch) { diff --git a/io.hpp b/io.hpp index 5f034316..37a7ce35 100644 --- a/io.hpp +++ b/io.hpp @@ -47,6 +47,8 @@ namespace util { fd (const char *path, int flags, mode_t mode = 0660); fd (const boost::filesystem::path&, int flags); + static fd dup (int); + ~fd (); operator int (void) const { return m_fd; }