From 072a356d728a6c461c4c909b6ff92b0089b810e8 Mon Sep 17 00:00:00 2001 From: Stephen Toth Date: Sat, 23 Sep 2023 17:32:00 -0400 Subject: [PATCH] change the child process io buffer to use heap memory --- src/main.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main.c b/src/main.c index ca421cb..555077a 100644 --- a/src/main.c +++ b/src/main.c @@ -69,11 +69,17 @@ size_t getuserinput(char* input_buffer, size_t max_buffer_size, int fd) { // go through the buffer and find the lines to be edited and print them after int processbufferpop(char *roll_buffer, size_t read_length) { - - /*for (int i; i<= read_length; i++){ - if (roll_buffer[i] = '\n'){ - } - }*/ + //this is where some optimization could come in with using malloc and then freeing subset of memory; dog garn dynamic memory allocation + int found_index; + char *found_char = strchr(roll_buffer, '\n'); + if (found_char != NULL){ + found_index = found_char - roll_buffer; + char to_process_string[]; + + } else { + //no more instances + + } write(STDOUT_FILENO, roll_buffer, read_length); write(STDOUT_FILENO, "\n", 1); @@ -107,8 +113,9 @@ int main(int argc, char *argv[]) { } //remainder is main is the parent process for processing input and shit - char child_out_roll_buffer[BUFCHUNKSIZE+BUFSAFEPAD] = {0}; fcntl(master, F_SETFL, O_NONBLOCK); + char *child_out_roll_buffer = (char*) malloc(sizeof(char) * (BUFCHUNKSIZE+BUFSAFEPAD+1)); + usleep(500*1000); while(1){ // ideally I would want to read from the pipe and buffer the output, rewriting the line on change