From b7503986eaf7786c43d875b9c17653b7b85e77e4 Mon Sep 17 00:00:00 2001 From: Mike Black W9MDB Date: Thu, 24 Feb 2022 17:34:49 -0600 Subject: [PATCH] Fix compilation on mingw for gmtime_r https://github.com/Hamlib/Hamlib/issues/813 --- security/security.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/security/security.c b/security/security.c index cd1d7dbd2..25215c5f9 100644 --- a/security/security.c +++ b/security/security.c @@ -28,6 +28,28 @@ #include "password.h" #include "../src/misc.h" +#if defined(_WIN32) +// gmtime_r can be defined by mingw +#ifndef gmtime_r +static struct tm *gmtime_r(const time_t *t, struct tm *r) +{ + // gmtime is threadsafe in windows because it uses TLS + struct tm *theTm = gmtime(t); + + if (theTm) + { + *r = *theTm; + return r; + } + else + { + return 0; + } +} +#endif // gmtime_r +#endif // _WIN32 + + // using tv_usec with a sleep gives a fairly good random number static int my_rand(int max) {