| ... | @@ -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 |
| 758 | | 758 | |
| 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]. |
| 761 | fn windowsCreateCommandLine(allocator: *mem.Allocator, argv: []const []const u8) ![]u8 { | 761 | fn 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(); |
| 764 | | 764 | const buf_stream = buf.outStream(); |
| 765 | var buf_stream = buf.outStream(); | | |
| 766 | | 765 | |
| 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 | } |
| 793 | | 792 | |
| 794 | return buf.toOwnedSlice(); | 793 | return buf.toOwnedSlice(); |