winapi_common
process_io.cpp
1 // Copyright (c) 2020 Egor Tensin <Egor.Tensin@gmail.com>
2 // This file is part of the "winapi-common" project.
3 // For details, see https://github.com/egor-tensin/winapi-common.
4 // Distributed under the MIT License.
5 
6 #include <winapi/file.hpp>
7 #include <winapi/handle.hpp>
8 #include <winapi/path.hpp>
9 #include <winapi/process_io.hpp>
10 
11 #include <string>
12 #include <utility>
13 
14 namespace winapi {
15 namespace process {
16 
17 Stdin::Stdin() : Stream{Handle::std_in()} {}
18 
19 Stdout::Stdout() : Stream{Handle::std_out()} {}
20 
21 Stderr::Stderr() : Stream{Handle::std_err()} {}
22 
23 Stdin::Stdin(const std::string& path) : Stream{File::open_r(path)} {}
24 
25 Stdin::Stdin(const CanonicalPath& path) : Stream{File::open_r(path)} {}
26 
27 Stdout::Stdout(const std::string& path) : Stream{File::open_w(path)} {}
28 
29 Stdout::Stdout(const CanonicalPath& path) : Stream{File::open_w(path)} {}
30 
31 Stderr::Stderr(const std::string& path) : Stream{File::open_w(path)} {}
32 
33 Stderr::Stderr(const CanonicalPath& path) : Stream{File::open_w(path)} {}
34 
35 Stdin::Stdin(Pipe& pipe) : Stream{std::move(pipe.read_end())} {
36  pipe.write_end().dont_inherit();
37 }
38 
39 Stdout::Stdout(Pipe& pipe) : Stream{std::move(pipe.write_end())} {
40  pipe.read_end().dont_inherit();
41 }
42 
43 Stderr::Stderr(Pipe& pipe) : Stream{std::move(pipe.write_end())} {
44  pipe.read_end().dont_inherit();
45 }
46 
47 void IO::close() {
48  std_in.handle.close();
49  std_out.handle.close();
50  std_err.handle.close();
51 }
52 
53 } // namespace process
54 } // namespace winapi
Absolute, canonical path.
Definition: path.hpp:13
File I/O.
Definition: file.hpp:29
HANDLE wrapper.
Definition: handle.hpp:25
void close()
Definition: handle.cpp:47
Anonymous pipe wrapper.
Definition: pipe.hpp:15
Handle & read_end()
Definition: pipe.hpp:21
Handle & write_end()
Definition: pipe.hpp:25