aboutsummaryrefslogtreecommitdiff
path: root/butl/process.ixx
blob: 3b7ed7d4901d28c3fb5631bcf21bbb7c77eeb1a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// file      : butl/process.ixx -*- C++ -*-
// copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
// license   : MIT; see accompanying LICENSE file

namespace butl
{
  inline process::
  process ()
      : handle (0),
        status (0), // This is a bit of an assumption.
        out_fd (-1),
        in_ofd (-1),
        in_efd (-1)
  {
  }

  inline process::
  process (char const* const args[], int in, int out, int err)
      : process (nullptr, args, in, out, err) {}

  inline process::
  process (char const* const args[], process& in, int out, int err)
      : process (nullptr, args, in, out, err) {}

  inline process::
  process (process&& p)
      : handle (p.handle),
        status (p.status),
        out_fd (p.out_fd),
        in_ofd (p.in_ofd),
        in_efd (p.in_efd)
  {
    p.handle = 0;
  }

  inline process& process::
  operator= (process&& p)
  {
    if (this != &p)
    {
      if (handle != 0)
        wait ();

      handle = p.handle;
      status = p.status;
      out_fd = p.out_fd;
      in_ofd = p.in_ofd;
      in_efd = p.in_efd;

      p.handle = 0;
    }

    return *this;
  }
}