mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-30 11:20:08 +00:00
use dynamic array instead of string builder
This commit is contained in:
@@ -398,8 +398,11 @@ process_exec :: proc(
|
|||||||
{
|
{
|
||||||
defer if err != nil { _ = process_kill(process) }
|
defer if err != nil { _ = process_kill(process) }
|
||||||
|
|
||||||
stdout_builder := strings.builder_make(allocator) or_return
|
stdout_b: [dynamic]byte
|
||||||
stderr_builder := strings.builder_make(allocator) or_return
|
stdout_b.allocator = allocator
|
||||||
|
|
||||||
|
stderr_b: [dynamic]byte
|
||||||
|
stderr_b.allocator = allocator
|
||||||
|
|
||||||
has_stdout, has_stderr: bool
|
has_stdout, has_stderr: bool
|
||||||
read_data: for !has_stdout || !has_stderr {
|
read_data: for !has_stdout || !has_stderr {
|
||||||
@@ -411,14 +414,12 @@ process_exec :: proc(
|
|||||||
has_data, err = pipe_has_data(stdout_r)
|
has_data, err = pipe_has_data(stdout_r)
|
||||||
if has_data {
|
if has_data {
|
||||||
n, err = read(stdout_r, buf[:])
|
n, err = read(stdout_r, buf[:])
|
||||||
if strings.write_bytes(&stdout_builder, buf[:n]) != n {
|
append(&stdout_b, ..buf[:n]) or_return
|
||||||
err = .Out_Of_Memory
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
switch err {
|
switch err {
|
||||||
case nil: // nothing
|
case nil: // nothing
|
||||||
case .EOF, .Broken_Pipe:
|
case .EOF, .Broken_Pipe:
|
||||||
stdout = stdout_builder.buf[:]
|
stdout = stdout_b[:]
|
||||||
has_stdout = true
|
has_stdout = true
|
||||||
case:
|
case:
|
||||||
return
|
return
|
||||||
@@ -429,14 +430,12 @@ process_exec :: proc(
|
|||||||
has_data, err = pipe_has_data(stderr_r)
|
has_data, err = pipe_has_data(stderr_r)
|
||||||
if has_data {
|
if has_data {
|
||||||
n, err = read(stderr_r, buf[:])
|
n, err = read(stderr_r, buf[:])
|
||||||
if strings.write_bytes(&stderr_builder, buf[:n]) != n {
|
append(&stderr_b, ..buf[:n]) or_return
|
||||||
err = .Out_Of_Memory
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
switch err {
|
switch err {
|
||||||
case nil: // nothing
|
case nil: // nothing
|
||||||
case .EOF, .Broken_Pipe:
|
case .EOF, .Broken_Pipe:
|
||||||
stderr = stderr_builder.buf[:]
|
stderr = stderr_b[:]
|
||||||
has_stderr = true
|
has_stderr = true
|
||||||
case:
|
case:
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user