authorgravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2020-03-07 15:42:10+11:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-04-01 10:36:38-04:00
log37e6a64690a257b4f5a9e3f234deb8b72e74ca54
treedd94cca0dce1c644a5e0e547575090dd1220ba4e
parentecbc235403eb424a40e111a8789ae3a32fd14edd
signaturelock-open Commit is signed but in an unrecognized format.

std: use Buffer.outStream in std/child_process.zig


1 files changed, 8 insertions(+), 9 deletions(-)

lib/std/child_process.zig+8-9
...@@ -758,37 +758,36 @@ fn windowsCreateProcess(app_name: [*:0]u16, cmd_line: [*:0]u16, envp_ptr: ?[*]u1...@@ -758,37 +758,36 @@ fn windowsCreateProcess(app_name: [*:0]u16, cmd_line: [*:0]u16, envp_ptr: ?[*]u1
758758
759/// Caller must dealloc.759/// Caller must dealloc.
760/// Guarantees a null byte at result[result.len].760/// Guarantees a null byte at result[result.len].
761fn windowsCreateCommandLine(allocator: *mem.Allocator, argv: []const []const u8) ![]u8 {761fn windowsCreateCommandLine(allocator: *mem.Allocator, argv: []const []const u8) ![:0]u8 {
762 var buf = try Buffer.initSize(allocator, 0);762 var buf = try Buffer.initSize(allocator, 0);
763 defer buf.deinit();763 defer buf.deinit();
764764 const buf_stream = buf.outStream();
765 var buf_stream = buf.outStream();
766765
767 for (argv) |arg, arg_i| {766 for (argv) |arg, arg_i| {
768 if (arg_i != 0) try buf.appendByte(' ');767 if (arg_i != 0) try buf_stream.writeByte(' ');
769 if (mem.indexOfAny(u8, arg, " \t\n\"") == null) {768 if (mem.indexOfAny(u8, arg, " \t\n\"") == null) {
770 try buf.append(arg);769 try buf_stream.writeAll(arg);
771 continue;770 continue;
772 }771 }
773 try buf.appendByte('"');772 try buf_stream.writeByte('"');
774 var backslash_count: usize = 0;773 var backslash_count: usize = 0;
775 for (arg) |byte| {774 for (arg) |byte| {
776 switch (byte) {775 switch (byte) {
777 '\\' => backslash_count += 1,776 '\\' => backslash_count += 1,
778 '"' => {777 '"' => {
779 try buf_stream.writeByteNTimes('\\', backslash_count * 2 + 1);778 try buf_stream.writeByteNTimes('\\', backslash_count * 2 + 1);
780 try buf.appendByte('"');779 try buf_stream.writeByte('"');
781 backslash_count = 0;780 backslash_count = 0;
782 },781 },
783 else => {782 else => {
784 try buf_stream.writeByteNTimes('\\', backslash_count);783 try buf_stream.writeByteNTimes('\\', backslash_count);
785 try buf.appendByte(byte);784 try buf_stream.writeByte(byte);
786 backslash_count = 0;785 backslash_count = 0;
787 },786 },
788 }787 }
789 }788 }
790 try buf_stream.writeByteNTimes('\\', backslash_count * 2);789 try buf_stream.writeByteNTimes('\\', backslash_count * 2);
791 try buf.appendByte('"');790 try buf_stream.writeByte('"');
792 }791 }
793792
794 return buf.toOwnedSlice();793 return buf.toOwnedSlice();