diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2017-12-14 14:24:38 +0200 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2017-12-15 13:38:33 +0300 |
commit | 53b4f58c78e21cbc442891c2ce2a2b99a32e47bc (patch) | |
tree | f2b892650367a44332d7a169ede8aa9e60e6a3c8 /libbutl/openssl.cxx | |
parent | ceb8f4abba2cfc7ac51385fa59693c641151c8d2 (diff) |
Add process::pipe struct, extend process API
Diffstat (limited to 'libbutl/openssl.cxx')
-rw-r--r-- | libbutl/openssl.cxx | 38 |
1 files changed, 24 insertions, 14 deletions
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; } } |