From 7ce74ce206065c3af0035583330b3c773086f21c Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 3 Nov 2016 00:44:53 +0300 Subject: Invent auto_fd, make use of it in fdstreams and process --- tests/fdstream/driver.cxx | 17 +++++++++-------- tests/process/driver.cxx | 25 ++++++++++++------------- 2 files changed, 21 insertions(+), 21 deletions(-) (limited to 'tests') diff --git a/tests/fdstream/driver.cxx b/tests/fdstream/driver.cxx index f77e2d5..4d72284 100644 --- a/tests/fdstream/driver.cxx +++ b/tests/fdstream/driver.cxx @@ -14,6 +14,7 @@ #include #include #include +#include // move() #include #include @@ -134,8 +135,8 @@ main (int argc, const char* argv[]) cout.flush (); // @@ MINGW GCC 4.9 doesn't implement this_thread. If ifdstream - // non-blocking read will ever be implemented use Win32 Sleep() - // instead. + // non-blocking read will ever be implemented on Windows use Win32 + // Sleep() instead. // #ifndef _WIN32 this_thread::sleep_for (chrono::milliseconds (50)); @@ -250,7 +251,7 @@ main (int argc, const char* argv[]) to_file (f, "", fdopen_mode::truncate); { - ifdstream ifs (-1, ifdstream::badbit); + ifdstream ifs (ifdstream::badbit); ifs.open (f); string s; @@ -258,7 +259,7 @@ main (int argc, const char* argv[]) } { - ifdstream ifs (-1, fdstream_mode::text, ifdstream::badbit); + ifdstream ifs (nullfd, fdstream_mode::text, ifdstream::badbit); ifs.open (f); string s; @@ -268,7 +269,7 @@ main (int argc, const char* argv[]) // Check creating unopened ofdstream with a non-default exception mask. // { - ofdstream ofs (-1, ifdstream::badbit); + ofdstream ofs (ifdstream::badbit); ofs.open (f); istringstream is; @@ -277,7 +278,7 @@ main (int argc, const char* argv[]) } { - ofdstream ofs (-1, fdstream_mode::binary, ifdstream::badbit); + ofdstream ofs (nullfd, fdstream_mode::binary, ifdstream::badbit); ofs.open (f); istringstream is; @@ -406,8 +407,8 @@ main (int argc, const char* argv[]) const char* args[] = {argv[0], "-c", nullptr}; process pr (args, -1, -1); - ofdstream os (pr.out_fd); - ifdstream is (pr.in_ofd, fdstream_mode::non_blocking); + ofdstream os (move (pr.out_fd)); + ifdstream is (move (pr.in_ofd), fdstream_mode::non_blocking); const string s ( "0123456789\nABCDEFGHIJKLMNOPQRSTUVWXYZ\nabcdefghijklmnopqrstuvwxyz"); diff --git a/tests/process/driver.cxx b/tests/process/driver.cxx index d59b1a7..bc75cc2 100644 --- a/tests/process/driver.cxx +++ b/tests/process/driver.cxx @@ -65,15 +65,15 @@ exec (const path& p, bool s; r = !pr.try_wait (s); // Couldn't exit as waiting for the input. - auto bin_mode = [bin](int fd) -> int - { - if (bin) - fdmode (fd, fdstream_mode::binary); + auto bin_mode = [bin](auto_fd fd) -> auto_fd + { + if (bin) + fdmode (fd.get (), fdstream_mode::binary); - return fd; - }; + return fd; + }; - ofdstream os (bin_mode (pr.out_fd)); + ofdstream os (bin_mode (move (pr.out_fd))); copy (in.begin (), in.end (), ostream_iterator (os)); os.close (); @@ -89,12 +89,11 @@ exec (const path& p, // overall pipeline looks like 'os -> pr -> pr2 -> pr3 -> is'. // process pr3 (cwd, args.data (), -1, -1, -2); - process pr2 (cwd, args.data (), pr, bin_mode (pr3.out_fd), -2); - bool cr (fdclose (pr3.out_fd)); - assert (cr); + process pr2 ( + cwd, args.data (), pr, bin_mode (move (pr3.out_fd)).get (), -2); - ifdstream is (bin_mode (pr3.in_ofd)); + ifdstream is (bin_mode (move (pr3.in_ofd))); o = vector ( (istreambuf_iterator (is)), istreambuf_iterator ()); @@ -104,7 +103,7 @@ exec (const path& p, } else { - ifdstream is (bin_mode (pr.in_ofd)); + ifdstream is (bin_mode (move (pr.in_ofd))); o = vector ( (istreambuf_iterator (is)), istreambuf_iterator ()); @@ -125,7 +124,7 @@ exec (const path& p, if (err && !out) { - ifdstream is (bin_mode (pr.in_efd)); + ifdstream is (bin_mode (move (pr.in_efd))); vector e ((istreambuf_iterator (is)), istreambuf_iterator ()); -- cgit v1.1