From 2fca31ccc14c0655a21bdc9058096107cd38a42c Mon Sep 17 00:00:00 2001 From: Toni Uhlig Date: Mon, 9 Aug 2021 16:14:37 +0200 Subject: Fixed Mingw64 build. * adapted to SonarCloud-CI workflow * removed broken and incomplete Windows example (tested on VS2017/VS2019) * removed unnecessary include (e.g. pthread.h for the library which does not make use of it) Signed-off-by: Toni Uhlig --- example/ndpiReader.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'example/ndpiReader.c') diff --git a/example/ndpiReader.c b/example/ndpiReader.c index 053dc2ec5..003e19803 100644 --- a/example/ndpiReader.c +++ b/example/ndpiReader.c @@ -37,6 +37,8 @@ #else #include #include +#include +#include #endif #include #include @@ -44,7 +46,6 @@ #include #include #include -#include #include #include #include "ndpi_api.h" @@ -52,7 +53,6 @@ #include "../src/lib/third_party/include/ahocorasick.h" #include #include -#include #include #include "reader_util.h" @@ -2996,9 +2996,23 @@ static void printResults(u_int64_t processing_time_usec, u_int64_t setup_time_us t = 0; b = 0; } - strftime(when, sizeof(when), "%d/%b/%Y %H:%M:%S", localtime_r(&pcap_start.tv_sec, &result)); +#ifdef WIN32 + /* localtime() on Windows is thread-safe */ + struct tm * tm_ptr = localtime(&pcap_start.tv_sec); + result = *tm_ptr; +#else + localtime_r(&pcap_start.tv_sec, &result); +#endif + strftime(when, sizeof(when), "%d/%b/%Y %H:%M:%S", &result); printf("\tAnalysis begin: %s\n", when); - strftime(when, sizeof(when), "%d/%b/%Y %H:%M:%S", localtime_r(&pcap_end.tv_sec, &result)); +#ifdef WIN32 + /* localtime() on Windows is thread-safe */ + tm_ptr = localtime(&pcap_end.tv_sec); + result = *tm_ptr; +#else + localtime_r(&pcap_end.tv_sec, &result); +#endif + strftime(when, sizeof(when), "%d/%b/%Y %H:%M:%S", &result); printf("\tAnalysis end: %s\n", when); printf("\tTraffic throughput: %s pps / %s/sec\n", formatPackets(t, buf), formatTraffic(b, 1, buf1)); printf("\tTraffic duration: %.3f sec\n", traffic_duration/1000000); @@ -4442,11 +4456,12 @@ int original_main(int argc, char **argv) { /** @brief Timezone **/ +#ifndef __GNUC__ struct timezone { int tz_minuteswest; /* minutes W of Greenwich */ int tz_dsttime; /* type of dst correction */ }; - +#endif /** @brief Set time -- cgit v1.2.3