From a7c386edc19f3ef121b037b60b02852ffbcd6d65 Mon Sep 17 00:00:00 2001 From: aggieNick02 Date: Fri, 2 Sep 2022 18:19:43 -0500 Subject: [PATCH] Fix log compression storage on windows Set the file open mode to be binary instead of text when dealing with compressed log files. This fixes log compression storage not working on windows, and lets the test added in PR https://github.com/axboe/fio/pull/1458 pass on windows. Signed-off-by: Nick Neumann --- iolog.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/iolog.c b/iolog.c index 41d3e473..aa9c3bb1 100644 --- a/iolog.c +++ b/iolog.c @@ -1218,7 +1218,7 @@ int iolog_file_inflate(const char *file) void *buf; FILE *f; - f = fopen(file, "r"); + f = fopen(file, "rb"); if (!f) { perror("fopen"); return 1; @@ -1300,10 +1300,21 @@ void flush_log(struct io_log *log, bool do_append) void *buf; FILE *f; + /* + * If log_gz_store is true, we are writing a binary file. + * Set the mode appropriately (on all platforms) to avoid issues + * on windows (line-ending conversions, etc.) + */ if (!do_append) - f = fopen(log->filename, "w"); + if (log->log_gz_store) + f = fopen(log->filename, "wb"); + else + f = fopen(log->filename, "w"); else - f = fopen(log->filename, "a"); + if (log->log_gz_store) + f = fopen(log->filename, "ab"); + else + f = fopen(log->filename, "a"); if (!f) { perror("fopen log"); return; -- 2.25.1