std: use Buffer.outStream in std/child_process.zig
This commit is contained in:
parent
ecbc235403
commit
37e6a64690
@ -758,37 +758,36 @@ fn windowsCreateProcess(app_name: [*:0]u16, cmd_line: [*:0]u16, envp_ptr: ?[*]u1
|
||||
|
||||
/// Caller must dealloc.
|
||||
/// Guarantees a null byte at result[result.len].
|
||||
fn windowsCreateCommandLine(allocator: *mem.Allocator, argv: []const []const u8) ![]u8 {
|
||||
fn windowsCreateCommandLine(allocator: *mem.Allocator, argv: []const []const u8) ![:0]u8 {
|
||||
var buf = try Buffer.initSize(allocator, 0);
|
||||
defer buf.deinit();
|
||||
|
||||
var buf_stream = buf.outStream();
|
||||
const buf_stream = buf.outStream();
|
||||
|
||||
for (argv) |arg, arg_i| {
|
||||
if (arg_i != 0) try buf.appendByte(' ');
|
||||
if (arg_i != 0) try buf_stream.writeByte(' ');
|
||||
if (mem.indexOfAny(u8, arg, " \t\n\"") == null) {
|
||||
try buf.append(arg);
|
||||
try buf_stream.writeAll(arg);
|
||||
continue;
|
||||
}
|
||||
try buf.appendByte('"');
|
||||
try buf_stream.writeByte('"');
|
||||
var backslash_count: usize = 0;
|
||||
for (arg) |byte| {
|
||||
switch (byte) {
|
||||
'\\' => backslash_count += 1,
|
||||
'"' => {
|
||||
try buf_stream.writeByteNTimes('\\', backslash_count * 2 + 1);
|
||||
try buf.appendByte('"');
|
||||
try buf_stream.writeByte('"');
|
||||
backslash_count = 0;
|
||||
},
|
||||
else => {
|
||||
try buf_stream.writeByteNTimes('\\', backslash_count);
|
||||
try buf.appendByte(byte);
|
||||
try buf_stream.writeByte(byte);
|
||||
backslash_count = 0;
|
||||
},
|
||||
}
|
||||
}
|
||||
try buf_stream.writeByteNTimes('\\', backslash_count * 2);
|
||||
try buf.appendByte('"');
|
||||
try buf_stream.writeByte('"');
|
||||
}
|
||||
|
||||
return buf.toOwnedSlice();
|
||||
|
Loading…
x
Reference in New Issue
Block a user