aboutsummaryrefslogtreecommitdiff
path: root/butl/fdstream
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2017-04-24 13:51:56 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2017-04-24 14:49:11 +0300
commitb8526f8f0cb24c457da8c88877e516943e3e1902 (patch)
treef63a266ab7710a21c3d1cbca132194b1c7ad5b5f /butl/fdstream
parenteb4810893eb4c8379c3455f1e8a75ccd3b911aa6 (diff)
Make fdnull() to return auto_fd
Diffstat (limited to 'butl/fdstream')
-rw-r--r--butl/fdstream17
1 files changed, 6 insertions, 11 deletions
diff --git a/butl/fdstream b/butl/fdstream
index afc3ef6..df39808 100644
--- a/butl/fdstream
+++ b/butl/fdstream
@@ -575,9 +575,8 @@ namespace butl
// Open the null device (e.g., /dev/null) that discards all data written to
// it and provides no data for read operations (i.e., yelds EOF on read).
- // Return file descriptor on success, set errno and return -1 otherwise.
- // Note that it's the caller's responsibility to close the returned file
- // descriptor.
+ // Return an auto_fd that holds its file descriptor on success and throwing
+ // ios::failure otherwise.
//
// On Windows the null device is NUL and writing anything substantial to it
// (like redirecting a process' output) is extremely slow, as in, an order
@@ -593,18 +592,14 @@ namespace butl
// and read from the descriptor.
//
// Note that on POSIX the FD_CLOEXEC flag is set for the file descriptor to
- // prevent its leakage into child processes.
- //
- // @@ You may have noticed that this interface doesn't match fdopen() (it
- // does not throw and return int instead of auto_fd). The reason for this
- // is process and its need to translate everything to process_error).
- // Once we solve that we can clean this up as well.
+ // prevent its leakage into child processes. On Windows, for the same
+ // purpose, the _O_NOINHERIT flag is set.
//
#ifndef _WIN32
- LIBBUTL_EXPORT int
+ LIBBUTL_EXPORT auto_fd
fdnull () noexcept;
#else
- LIBBUTL_EXPORT int
+ LIBBUTL_EXPORT auto_fd
fdnull (bool temp = false) noexcept;
#endif