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
758758
759759/// Caller must dealloc.
760760/// 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 {
762762 var buf = try Buffer.initSize(allocator, 0);
763763 defer buf.deinit();
764
765 var buf_stream = buf.outStream();
764 const buf_stream = buf.outStream();
766765
767766 for (argv) |arg, arg_i| {
768 if (arg_i != 0) try buf.appendByte(' ');
767 if (arg_i != 0) try buf_stream.writeByte(' ');
769768 if (mem.indexOfAny(u8, arg, " \t\n\"") == null) {
770 try buf.append(arg);
769 try buf_stream.writeAll(arg);
771770 continue;
772771 }
773 try buf.appendByte('"');
772 try buf_stream.writeByte('"');
774773 var backslash_count: usize = 0;
775774 for (arg) |byte| {
776775 switch (byte) {
777776 '\\' => backslash_count += 1,
778777 '"' => {
779778 try buf_stream.writeByteNTimes('\\', backslash_count * 2 + 1);
780 try buf.appendByte('"');
779 try buf_stream.writeByte('"');
781780 backslash_count = 0;
782781 },
783782 else => {
784783 try buf_stream.writeByteNTimes('\\', backslash_count);
785 try buf.appendByte(byte);
784 try buf_stream.writeByte(byte);
786785 backslash_count = 0;
787786 },
788787 }
789788 }
790789 try buf_stream.writeByteNTimes('\\', backslash_count * 2);
791 try buf.appendByte('"');
790 try buf_stream.writeByte('"');
792791 }
793792
794793 return buf.toOwnedSlice();