From 53b4f58c78e21cbc442891c2ce2a2b99a32e47bc Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 14 Dec 2017 14:24:38 +0200 Subject: Add process::pipe struct, extend process API --- libbutl/openssl.cxx | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) (limited to 'libbutl/openssl.cxx') diff --git a/libbutl/openssl.cxx b/libbutl/openssl.cxx index 89cf8ed..48b0c1d 100644 --- a/libbutl/openssl.cxx +++ b/libbutl/openssl.cxx @@ -36,21 +36,24 @@ using namespace std; namespace butl { - int openssl:: + process::pipe openssl:: map_in (nullfd_t, io_data& d) { d.pipe.in = fdnull (); // /dev/null - return d.pipe.in.get (); + return pipe (d.pipe); } - int openssl:: + process::pipe openssl:: map_in (const path& f, io_data& d) { + pipe r; if (f.string () == "-") { // Note: no need for any options, openssl reads from stdin by default. // d.pipe = fdopen_pipe (fdopen_mode::binary); + r = pipe (d.pipe); + out.open (move (d.pipe.out)); } else @@ -58,12 +61,13 @@ namespace butl d.options.push_back ("-in"); d.options.push_back (f.string ().c_str ()); d.pipe.in = fdnull (); // /dev/null + r = pipe (d.pipe); } - return d.pipe.in.get (); + return r; } - int openssl:: + process::pipe openssl:: map_in (fdstream_mode m, io_data& d) { assert (m == fdstream_mode::text || m == fdstream_mode::binary); @@ -73,26 +77,30 @@ namespace butl d.pipe = fdopen_pipe (m == fdstream_mode::binary ? fdopen_mode::binary : fdopen_mode::none); - + pipe r (d.pipe); + out.open (move (d.pipe.out)); - return d.pipe.in.get (); + return r; } - int openssl:: + process::pipe openssl:: map_out (nullfd_t, io_data& d) { d.pipe.out = fdnull (); - return d.pipe.out.get (); // /dev/null + return pipe (d.pipe); // /dev/null } - int openssl:: + process::pipe openssl:: map_out (const path& f, io_data& d) { + pipe r; if (f.string () == "-") { // Note: no need for any options, openssl writes to stdout by default. // d.pipe = fdopen_pipe (fdopen_mode::binary); + r = pipe (d.pipe); + in.open (move (d.pipe.in), fdstream_mode::skip); } else @@ -100,12 +108,13 @@ namespace butl d.options.push_back ("-out"); d.options.push_back (f.string ().c_str ()); d.pipe.out = fdnull (); // /dev/null + r = pipe (d.pipe); } - return d.pipe.out.get (); + return r; } - int openssl:: + process::pipe openssl:: map_out (fdstream_mode m, io_data& d) { assert (m == fdstream_mode::text || m == fdstream_mode::binary); @@ -115,8 +124,9 @@ namespace butl d.pipe = fdopen_pipe (m == fdstream_mode::binary ? fdopen_mode::binary : fdopen_mode::none); - + pipe r (d.pipe); + in.open (move (d.pipe.in), fdstream_mode::skip); - return d.pipe.out.get (); + return r; } } -- cgit v1.1