From 0f3f611508fbd4ad0704f1e1352fcbdd7ee512c7 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 7 Mar 2025 22:41:56 +0100 Subject: Improve portability MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- solar.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/solar.c b/solar.c index 97c6dd7..697c960 100644 --- a/solar.c +++ b/solar.c @@ -26,6 +26,46 @@ double libred_solar_elevation(double latitude, double longitude, double *elevation); +#if !defined(_POSIX_TIMERS) +# ifndef CLOCK_REALTIME_COARSE +# define CLOCK_REALTIME_COARSE 0 +# endif +# ifndef CLOCK_REALTIME +# define CLOCK_REALTIME 0 +# endif +# if defined(_WIN32) +# include +int +clock_gettime(int clockid, struct timespec *ts) +{ + /* https://learn.microsoft.com/en-us/windows/win32/sysinfo/file-times */ + FILETIME ft; + ULARGE_INTEGER u64; + (void) clockid; + GetSystemTimePreciseAsFileTime(&ft); + u64.LowPart = ft.dwLowDateTime; + u64.HighPart = ft.dwHighDateTime; + ts->tv_sec = (time_t)(uli.QuadPart / 100000000ULL - 11644473600ULL); + ts->tv_nsec = (long)(uli.QuadPart % 100000000ULL * 10ULL); + return 0; +} +# else +# include +int +clock_gettime(int clockid, struct timespec *ts) +{ + struct timeval tv; + (void) clockid; + if (gettimeofday(&tv, NULL)) + return -1; + ts->tv_sec = tv.tv_sec; + ts->tv_nsec = tv.tv_usec * 1000; + return 0; +} +# endif +#endif + + /** * Get current Julian Centuries time (100 Julian Days since J2000) * and Julian Day time -- cgit v1.2.3-70-g09d2