aboutsummaryrefslogtreecommitdiff
path: root/butl/fdstream.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2016-11-08 16:09:37 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2016-11-08 16:09:37 +0300
commit2940072ad2e4a074da9b091fce89adc50e29c6e0 (patch)
treeb2cb66ed02762d525d2b82aecf6c95db8e119401 /butl/fdstream.cxx
parentce9d743824be796471bae9b57c0185ef8ec1b804 (diff)
Add fddup()
Diffstat (limited to 'butl/fdstream.cxx')
-rw-r--r--butl/fdstream.cxx20
1 files changed, 17 insertions, 3 deletions
diff --git a/butl/fdstream.cxx b/butl/fdstream.cxx
index 102ad66..16801ed 100644
--- a/butl/fdstream.cxx
+++ b/butl/fdstream.cxx
@@ -6,14 +6,14 @@
#ifndef _WIN32
# include <fcntl.h> // open(), O_*, fcntl()
-# include <unistd.h> // close(), read(), write(), lseek(), ssize_t,
+# include <unistd.h> // close(), read(), write(), lseek(), dup(), ssize_t,
// STD*_FILENO
# include <sys/uio.h> // writev(), iovec
# include <sys/stat.h> // S_I*
# include <sys/types.h> // off_t
#else
# include <io.h> // _close(), _read(), _write(), _setmode(), _sopen(),
- // _lseek()
+ // _lseek(), _dup()
# include <share.h> // _SH_DENYNO
# include <stdio.h> // _fileno(), stdin, stdout, stderr
# include <fcntl.h> // _O_*
@@ -87,7 +87,6 @@ namespace butl
}
}
-
// fdbuf
//
fdbuf::
@@ -737,6 +736,21 @@ namespace butl
return auto_fd (fd);
}
+ auto_fd
+ fddup (int fd)
+ {
+#ifndef _WIN32
+ int nfd (dup (fd));
+#else
+ int nfd (_dup (fd));
+#endif
+
+ if (nfd == -1)
+ throw_ios_failure (errno);
+
+ return auto_fd (nfd);
+ }
+
#ifndef _WIN32
bool