summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEmil Engler <me@emilengler.com>2022-12-11 18:08:17 +0100
committerDaniel Stenberg <daniel@haxx.se>2022-12-12 09:04:51 +0100
commit8b1e5df73decb3920ca5476710ee89e1495bb760 (patch)
tree5d9b6d9820999377bfe969e480e7b405f813fae7 /src
parent1a88b6b6537fd5297a9c4ad0a53d6cef5f1a83fa (diff)
downloadcurl-8b1e5df73decb3920ca5476710ee89e1495bb760.tar.gz
tool: determine the correct fopen option for -D
This commit fixes a bug in the dump-header feature regarding the determination of the second fopen(3) option. Reported-by: u20221022 on github See #4753 See #4762 Fixes #10074 Closes #10079
Diffstat (limited to 'src')
-rw-r--r--src/tool_operate.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/tool_operate.c b/src/tool_operate.c
index 7af73a266..79db063a5 100644
--- a/src/tool_operate.c
+++ b/src/tool_operate.c
@@ -969,7 +969,21 @@ static CURLcode single_transfer(struct GlobalConfig *global,
/* open file for output: */
if(strcmp(config->headerfile, "-")) {
FILE *newfile;
- newfile = fopen(config->headerfile, per->prev == NULL?"wb":"ab");
+
+ /*
+ * this checks if the previous transfer had the same
+ * OperationConfig, which would mean, that the an output file has
+ * already been created and data can be appened to it, instead
+ * of overwriting it.
+ * TODO: Consider placing the file handle inside the
+ * OperationConfig, so that it does not need to be opened/closed
+ * for every transfer.
+ */
+ if(per->prev && per->prev->config == config)
+ newfile = fopen(config->headerfile, "ab+");
+ else
+ newfile = fopen(config->headerfile, "wb+");
+
if(!newfile) {
warnf(global, "Failed to open %s\n", config->headerfile);
result = CURLE_WRITE_ERROR;