From b7f32cea30174e391027fecc9d431ca16b2f87c2 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 25 Oct 2022 10:24:53 +0200 Subject: All passing to process ownership to one end of pipe --- libbutl/process.ixx | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'libbutl/process.ixx') diff --git a/libbutl/process.ixx b/libbutl/process.ixx index 256454b..0f04127 100644 --- a/libbutl/process.ixx +++ b/libbutl/process.ixx @@ -124,6 +124,42 @@ namespace butl } #endif + // process::pipe + // + inline process::pipe:: + pipe (pipe&& p) + : in (p.in), out (p.out), own_in (p.own_in), own_out (p.own_out) + { + p.in = p.out = -1; + } + + inline process::pipe& process::pipe:: + operator= (pipe&& p) + { + if (this != &p) + { + int d (own_in ? in : own_out ? out : -1); + if (d != -1) + fdclose (d); + + in = p.in; + out = p.out; + own_in = p.own_in; + own_out = p.own_out; + + p.in = p.out = -1; + } + return *this; + } + + inline process::pipe:: + ~pipe () + { + int d (own_in ? in : own_out ? out : -1); + if (d != -1) + fdclose (d); + } + // process // #ifndef _WIN32 -- cgit v1.1