From c1d22e2a445c48e999242515839df4676c08b1bd Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Sat, 31 Jul 2021 08:22:27 +0200 Subject: [PATCH] change: write file with filearray handler --- splitter.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/splitter.c b/splitter.c index 091feeb..db225d5 100644 --- a/splitter.c +++ b/splitter.c @@ -6,12 +6,12 @@ #include "discspan.h" #include "splitter.h" -void writeOutputFile(const char *outputPath, file_size_t *disc, int length) +void writeOutputFile(const char *outputPath, file_size_handler_t disc) { FILE *out = fopen(outputPath, "w"); - for (int i = 0; i < length; i++) { - fprintf(out, "%s\n", disc[i].name); + for (int i = 0; i < disc.length; i++) { + fprintf(out, "%s\n", disc.filearray[i].name); } fclose(out); @@ -27,8 +27,11 @@ void splitter(file_size_handler_t *handler, const char *output, unsigned long lo { file_size_t *rest = (file_size_t *) malloc(handler->length * sizeof(file_size_t)); - file_size_t *disc = (file_size_t *) - malloc(handler->length * sizeof(file_size_t)); + + file_size_handler_t disc; + disc.length = handler->length; + disc.filearray = (file_size_t *) + malloc(disc.length * sizeof(file_size_t)); unsigned long long filesize = 0; int restcount = 0; @@ -40,13 +43,17 @@ void splitter(file_size_handler_t *handler, const char *output, unsigned long lo if (splitgroesse >= filesize) { splitgroesse -= filesize; - disc[disccount++] = handler->filearray[i]; + disc.filearray[disccount++] = handler->filearray[i]; } else { rest[restcount++] = handler->filearray[i]; } } - writeOutputFile(output, disc, disccount); + disc.length = disccount; + disc.filearray = (file_size_t *) + realloc(disc.filearray, disc.length * sizeof(file_size_t)); + + writeOutputFile(output, disc); onPrintEvent(output, splitgroesse); @@ -55,6 +62,6 @@ void splitter(file_size_handler_t *handler, const char *output, unsigned long lo restcount * sizeof(file_size_t)); handler->length = restcount; - free(disc); + free(disc.filearray); free(rest); } -- 2.39.5