From 676f6520bf76867135f1af4fab5d69b3b212d198 Mon Sep 17 00:00:00 2001 From: Aleksey Veresov Date: Fri, 29 Nov 2019 23:33:09 +0300 Subject: [magi] Finally done. (Probably. =) ) --- src/request.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/request.c') diff --git a/src/request.c b/src/request.c index 99f3a2a..e905e53 100644 --- a/src/request.c +++ b/src/request.c @@ -41,9 +41,9 @@ void magi_tempfiles_add(struct magi_tempfiles * tmps, tmps->locations = malloc(sizeof(*tmps->locations)); tmps->maximums = malloc(sizeof(*tmps->maximums)); } - tmps->param_names[tmps->count] = name; - tmps->locations[tmps->count] = path; - tmps->maximums[tmps->count] = max; + tmps->param_names[tmps->count - 1] = name; + tmps->locations[tmps->count - 1] = path; + tmps->maximums[tmps->count - 1] = max; } static void tempfiles(struct magi_file * file, @@ -57,16 +57,21 @@ static void tempfiles(struct magi_file * file, for (pos = 0; pos != table->count; ++pos) { if (!strcmp(table->param_names[pos], file->param_name)) { static FILE * f = 0; + static int unlimited; static int left; - int min; if (!f) { const char * loc = table->locations[pos]; f = fopen(loc, "wb"); left = table->maximums[pos]; + unlimited = !left; + } + if (unlimited) { + fwrite(addon, 1, addon_len, f); + } else { + int min = left < addon_len ? left : addon_len; + fwrite(addon, 1, min, f); + left -= min; } - min = left < addon_len ? left : addon_len; - fwrite(addon, 1, min, f); - left -= min; if (is_addon_last) { fclose(f); f = 0; -- cgit v1.2.3