From d8614a15c6b65c588eadddb5233dc9d0b304de04 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Tue, 18 Jun 2019 15:58:36 +0200 Subject: [PATCH] mingw: fix compile error Declare _POSIX_C_SOURCE before sys/time.h to avoid: util-time.c: In function 'SCUtcTime': util-time.c:222:12: error: implicit declaration of function 'gmtime_r'; did you mean 'gmtime_s'? [-Werror=implicit-function-declaration] 222 | return gmtime_r(&timep, result); | ^~~~~~~~ | gmtime_s util-time.c:222:12: warning: returning 'int' from a function with return type 'struct tm *' makes pointer from integer without a cast [-Wint-conversion] 222 | return gmtime_r(&timep, result); | ^~~~~~~~~~~~~~~~~~~~~~~~ util-time.c: In function 'SCLocalTime': util-time.c:305:9: error: implicit declaration of function 'localtime_r'; did you mean 'localtime_s'? [-Werror=implicit-function-declaration] 305 | localtime_r(&timep, &cached_local_tm[lru]); | ^~~~~~~~~~~ | localtime_s util-time.c:321:56: warning: comparison between pointer and integer 321 | if (localtime_r(&timep, &cached_local_tm[lru]) == NULL) | ^~ cc1.exe: some warnings being treated as errors Tickets: #2994 #3051 --- src/util-time.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/util-time.c b/src/util-time.c index b41bd37490..f1a1834ca0 100644 --- a/src/util-time.c +++ b/src/util-time.c @@ -50,6 +50,14 @@ * would be considered timed out. */ +#ifdef OS_WIN32 +/* for MinGW we need to set _POSIX_C_SOURCE before including + * sys/time.h. */ +#ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L +#endif +#endif + #include "suricata-common.h" #include "detect.h" #include "threads.h"