Speedup run_command

This commit is contained in:
TheBrokenRail 2022-03-16 19:51:33 -04:00
parent 59b8fd9f54
commit a40da62b70

View File

@ -95,10 +95,12 @@ char *run_command(const char *const command[], int *return_code) {
// Read stdout
close(output_pipe[1]);
char *output = NULL;
char c;
#define BUFFER_SIZE 1024
char buf[BUFFER_SIZE];
int bytes_read = 0;
while ((bytes_read = read(output_pipe[0], (void *) &c, 1)) > 0) {
string_append(&output, "%c", c);
while ((bytes_read = read(output_pipe[0], (void *) buf, BUFFER_SIZE - 1 /* Account For NULL-Terminator */)) > 0) {
buf[bytes_read] = '\0';
string_append(&output, "%s", buf);
}
close(output_pipe[0]);