@@ -32,7 +32,7 @@ pub fn main() !void {
3232 const child_path = it .next () orelse unreachable ;
3333
3434 // use posix convention: 0 read, 1 write
35- var pipe : if (builtin.os.tag == .windows ) [2 ]? windows .HANDLE else [2 ]os .fd_t = undefined ;
35+ var pipe : if (builtin.os.tag == .windows ) [2 ]windows .HANDLE else [2 ]os .fd_t = undefined ;
3636 if (builtin .os .tag == .windows ) {
3737 const saAttr = windows.SECURITY_ATTRIBUTES {
3838 .nLength = @sizeOf (windows .SECURITY_ATTRIBUTES ),
@@ -47,12 +47,7 @@ pub fn main() !void {
4747
4848 // write read side of pipe to string + add to spawn command
4949 var buf : [handleCharSize ]u8 = comptime [_ ]u8 {0 } ** handleCharSize ;
50- const s_handle =
51- if (builtin .os .tag == .windows )
52- try handleToString (pipe [0 ].? , & buf )
53- else
54- try handleToString (pipe [0 ], & buf );
55-
50+ const s_handle = try handleToString (pipe [0 ], & buf );
5651 var child_proc = ChildProcess .init (
5752 &.{ child_path , s_handle },
5853 gpa ,
@@ -62,15 +57,12 @@ pub fn main() !void {
6257 if (os .hasPosixSpawn ) child_proc .posix_actions = try os .posix_spawn .Actions .init ();
6358 defer if (os .hasPosixSpawn ) child_proc .posix_actions .? .deinit ();
6459 if (os .hasPosixSpawn ) try child_proc .posix_actions .? .close (pipe [1 ]); // TODO: This is not closed in child
65- defer if (builtin .os .tag == .windows )
66- os .close (pipe [0 ].? )
67- else
68- os .close (pipe [0 ]);
60+ defer os .close (pipe [0 ]);
6961
7062 try child_proc .spawn ();
7163 }
7264
73- // call fcntl on Unixes to disable handle inheritance
65+ // call fcntl on Unixes to disable handle inheritance (windows one is per default not enabled)
7466 if (builtin .os .tag != .windows ) {
7567 try std .os .disableFileInheritance (pipe [1 ]);
7668 }
@@ -85,11 +77,7 @@ pub fn main() !void {
8577 try std .testing .expect ((fcntl_flags & os .FD_CLOEXEC ) != 0 );
8678 }
8779
88- var file_out = if (builtin .target .os .tag == .windows )
89- std.fs.File { .handle = pipe [1 ].? }
90- else
91- std.fs.File { .handle = pipe [1 ] };
92-
80+ var file_out = std.fs.File { .handle = pipe [1 ] };
9381 defer file_out .close ();
9482 const file_out_writer = file_out .writer ();
9583 try file_out_writer .writeAll ("test123\x17 " ); // ETB = \x17
0 commit comments