aboutsummaryrefslogtreecommitdiff
path: root/butl/fdstream.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2016-06-03 14:20:50 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2016-06-03 21:18:22 +0300
commit265c3c71a82906de252637ecbdacf23a99b2ea0c (patch)
treeed54306dedb101208a0fea220ec230d9f0e1c2da /butl/fdstream.cxx
parent08c7238ae6be49d6eb51099107538f5a4522f9dd (diff)
Add fdnull()
Diffstat (limited to 'butl/fdstream.cxx')
-rw-r--r--butl/fdstream.cxx16
1 files changed, 15 insertions, 1 deletions
diff --git a/butl/fdstream.cxx b/butl/fdstream.cxx
index d99be70..13becfa 100644
--- a/butl/fdstream.cxx
+++ b/butl/fdstream.cxx
@@ -5,9 +5,11 @@
#include <butl/fdstream>
#ifndef _WIN32
+# include <fcntl.h> // open(), O_RDWR
# include <unistd.h> // close(), read(), write()
#else
-# include <io.h> // _close(), _read(), _write(), _setmode()
+# include <io.h> // _close(), _read(), _write(), _setmode(), _sopen()
+# include <share.h> // _SH_DENYNO
# include <stdio.h> // _fileno(), stdin, stdout, stderr
# include <fcntl.h> // _O_BINARY, _O_TEXT
#endif
@@ -153,6 +155,12 @@ namespace butl
return close (fd) == 0;
}
+ int
+ fdnull () noexcept
+ {
+ return open ("/dev/null", O_RDWR);
+ }
+
fdtranslate
fdmode (int, fdtranslate)
{
@@ -185,6 +193,12 @@ namespace butl
return _close (fd) == 0;
}
+ int
+ fdnull () noexcept
+ {
+ return _sopen ("nul", _O_RDWR, _SH_DENYNO);
+ }
+
fdtranslate
fdmode (int fd, fdtranslate m)
{