aboutsummaryrefslogtreecommitdiff
path: root/src/Program.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Program.cpp')
-rw-r--r--src/Program.cpp9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/Program.cpp b/src/Program.cpp
index 136a494..d9927af 100644
--- a/src/Program.cpp
+++ b/src/Program.cpp
@@ -86,7 +86,7 @@ int exec_program_pipe(const char **args, ReadProgram *read_program) {
}
}
-int exec_program(const char **args, ProgramOutputCallback output_callback, void *userdata) {
+int exec_program(const char **args, ProgramOutputCallback output_callback, void *userdata, int buffer_size) {
ReadProgram read_program;
int res = exec_program_pipe(args, &read_program);
if(res != 0)
@@ -96,10 +96,11 @@ int exec_program(const char **args, ProgramOutputCallback output_callback, void
int status;
int exit_status;
- char buffer[4097];
+ assert(buffer_size >= 1 && buffer_size <= 65536);
+ char *buffer = (char*)alloca(buffer_size + 1);
for(;;) {
- ssize_t bytes_read = read(read_program.read_fd, buffer, sizeof(buffer) - 1);
+ ssize_t bytes_read = read(read_program.read_fd, buffer, buffer_size);
if(bytes_read == 0) {
break;
} else if(bytes_read == -1) {
@@ -109,8 +110,6 @@ int exec_program(const char **args, ProgramOutputCallback output_callback, void
break;
}
- //check if running. Also do the same in download_to_json
-
buffer[bytes_read] = '\0';
if(output_callback) {
result = output_callback(buffer, bytes_read, userdata);