Use workaround for setvbuf on Windows in DebugLogger/Extract file analyzer

This commit is contained in:
Tim Wojtulewicz 2023-04-30 11:30:49 -07:00
parent f2a3e23dfa
commit 29b0380815
3 changed files with 3 additions and 11 deletions

View file

@ -56,7 +56,7 @@ void DebugLogger::OpenDebugLog(const char* filename)
} }
} }
setvbuf(file, NULL, _IOLBF, 0); util::detail::setvbuf(file, NULL, _IOLBF, 0);
} }
else else
file = stderr; file = stderr;

View file

@ -202,16 +202,8 @@ void File::SetBuf(bool arg_buffered)
if ( ! f ) if ( ! f )
return; return;
#ifndef _MSC_VER if ( util::detail::setvbuf(f, NULL, arg_buffered ? _IOFBF : _IOLBF, 0) != 0 )
if ( setvbuf(f, NULL, arg_buffered ? _IOFBF : _IOLBF, 0) != 0 )
reporter->Error("setvbuf failed"); 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; buffered = arg_buffered;
} }

View file

@ -23,7 +23,7 @@ Extract::Extract(RecordValPtr args, file_analysis::File* file, const std::string
if ( file_stream ) if ( file_stream )
{ {
// Try to ensure full buffering. // 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)); util::zeek_strerror_r(errno, buf, sizeof(buf));
reporter->Warning("cannot set buffering mode for %s: %s", filename.data(), buf); reporter->Warning("cannot set buffering mode for %s: %s", filename.data(), buf);