From 6c8e3f09c185d7fa4664ccd9e5c4f623a17b84cc Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Tue, 12 Jul 2016 17:24:00 +0300 Subject: Extend fdstream --- butl/pager.cxx | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'butl/pager.cxx') diff --git a/butl/pager.cxx b/butl/pager.cxx index 0f29bb4..3d429f5 100644 --- a/butl/pager.cxx +++ b/butl/pager.cxx @@ -5,20 +5,20 @@ #include #ifndef _WIN32 -# include // close(), STDOUT_FILENO +# include // STDOUT_FILENO # include // ioctl() # include # include // this_thread::sleep_for() #else # include - -# include // _close() #endif #include // strchr() #include +#include // fdclose() + using namespace std; namespace butl @@ -130,11 +130,8 @@ namespace butl bool r; if (p_.try_wait (r)) { -#ifndef _WIN32 - close (p_.out_fd); -#else - _close (p_.out_fd); -#endif + fdclose (p_.out_fd); + if (pager != nullptr) throw system_error (ECHILD, system_category ()); } @@ -162,7 +159,7 @@ namespace butl } bool pager:: - wait () + wait (bool ie) { // Teardown the indentation machinery. // @@ -172,8 +169,13 @@ namespace butl buf_ = nullptr; } + // Prevent ofdstream::close() from throwing in the ignore errors mode. + // + if (ie) + os_.exceptions (ofdstream::goodbit); + os_.close (); - return p_.wait (); + return p_.wait (ie); } pager::int_type pager:: -- cgit v1.1