io: add static dup method to fd

This commit is contained in:
Danny Robson 2016-08-29 16:14:12 +10:00
parent ce2f3b821b
commit 1b118ff377
2 changed files with 14 additions and 0 deletions

12
io.cpp
View File

@ -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 int
indenter::overflow (int ch) { indenter::overflow (int ch) {

2
io.hpp
View File

@ -47,6 +47,8 @@ namespace util {
fd (const char *path, int flags, mode_t mode = 0660); fd (const char *path, int flags, mode_t mode = 0660);
fd (const boost::filesystem::path&, int flags); fd (const boost::filesystem::path&, int flags);
static fd dup (int);
~fd (); ~fd ();
operator int (void) const { return m_fd; } operator int (void) const { return m_fd; }