From f2a3e23dfadbd8a3df5e79b6ca7a39d19cfbead7 Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Tue, 2 May 2023 09:38:42 -0700 Subject: [PATCH] Add ifdef'd implementation of setvbuf to zeek::util --- src/util.cc | 12 ++++++++++++ src/util.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/src/util.cc b/src/util.cc index f19e1c0ba0..f13bd3048a 100644 --- a/src/util.cc +++ b/src/util.cc @@ -996,6 +996,18 @@ void set_thread_name(const char* name, pthread_t tid) #endif } +int setvbuf(FILE* stream, char* buf, int type, size_t size) + { +#ifndef _MSC_VER + return ::setvbuf(stream, NULL, type, size); +#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. + return ::setvbuf(stream, NULL, _IONBF, 0); +#endif + } + } // namespace detail TEST_CASE("util get_unescaped_string") diff --git a/src/util.h b/src/util.h index 3988199368..09ebb0eca7 100644 --- a/src/util.h +++ b/src/util.h @@ -305,6 +305,8 @@ double parse_rotate_base_time(const char* rotate_base_time); // This function is thread-safe. double calc_next_rotate(double current, double rotate_interval, double base); +int setvbuf(FILE* stream, char* buf, int type, size_t size); + } // namespace detail template void delete_each(T* t)