]> gitweb.hhaalo.de Git - discspan.git/commitdiff
change: write file with filearray handler
authorBastian Dehn <hhaalo@arcor.de>
Sat, 31 Jul 2021 06:22:27 +0000 (08:22 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 31 Jul 2021 06:22:27 +0000 (08:22 +0200)
splitter.c

index 091feebb6376626fdc87e74eb97aa6d81a3be86d..db225d5c96aca96fae8b1d9184d1d378f0b63580 100644 (file)
@@ -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);
 }