From 29b038081533c6cc679f506e9b2e78dd6359b2e0 Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Sun, 30 Apr 2023 11:30:49 -0700 Subject: [PATCH] Use workaround for setvbuf on Windows in DebugLogger/Extract file analyzer --- src/DebugLogger.cc | 2 +- src/File.cc | 10 +--------- src/file_analysis/analyzer/extract/Extract.cc | 2 +- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/DebugLogger.cc b/src/DebugLogger.cc index 4ff950c377..a7b2a41dfe 100644 --- a/src/DebugLogger.cc +++ b/src/DebugLogger.cc @@ -56,7 +56,7 @@ void DebugLogger::OpenDebugLog(const char* filename) } } - setvbuf(file, NULL, _IOLBF, 0); + util::detail::setvbuf(file, NULL, _IOLBF, 0); } else file = stderr; diff --git a/src/File.cc b/src/File.cc index 44c78ccd91..864a0cc37f 100644 --- a/src/File.cc +++ b/src/File.cc @@ -202,16 +202,8 @@ void File::SetBuf(bool arg_buffered) if ( ! f ) return; -#ifndef _MSC_VER - if ( setvbuf(f, NULL, arg_buffered ? _IOFBF : _IOLBF, 0) != 0 ) + if ( util::detail::setvbuf(f, NULL, arg_buffered ? _IOFBF : _IOLBF, 0) != 0 ) reporter->Error("setvbuf failed"); -#else - // TODO: this turns off buffering altogether because Windows wants us to pass a valid - // buffer and length if we're going to pass one of the other modes. We need to - // investigate the performance ramifications of this. - if ( setvbuf(f, NULL, _IONBF, 0) != 0 ) - reporter->Error("setvbuf failed"); -#endif buffered = arg_buffered; } diff --git a/src/file_analysis/analyzer/extract/Extract.cc b/src/file_analysis/analyzer/extract/Extract.cc index 77a696daf3..e6805b867a 100644 --- a/src/file_analysis/analyzer/extract/Extract.cc +++ b/src/file_analysis/analyzer/extract/Extract.cc @@ -23,7 +23,7 @@ Extract::Extract(RecordValPtr args, file_analysis::File* file, const std::string if ( file_stream ) { // Try to ensure full buffering. - if ( setvbuf(file_stream, nullptr, _IOFBF, BUFSIZ) ) + if ( util::detail::setvbuf(file_stream, nullptr, _IOFBF, BUFSIZ) ) { util::zeek_strerror_r(errno, buf, sizeof(buf)); reporter->Warning("cannot set buffering mode for %s: %s", filename.data(), buf);