From a5b51669fb3997441ef5a3e74357bc61019ff015 Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Wed, 19 Mar 2025 11:58:05 -0400
Subject: [PATCH] time: Fix compilation on Solaris
The tm_gmtoff field of the broken-down time 'tm' struct wasn't formally standardized until POSIX.1-2024, but practically it has been available on desktop *nix platforms such as Linux/glibc, FreeBSD, OpenBSD, NetBSD, OSX/macOS (NextStep before that), and others since the 1990s. The notable exception is SunOS/Solaris, where the timezone offset must still be retrieved in the strictly POSIX.1-2008 compliant way.
(cherry picked from commit 7b93a744c8f0373f72be997e8a9c2f8a5b8aa05a)
---
src/time/unix/SDL_systime.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/src/time/unix/SDL_systime.c b/src/time/unix/SDL_systime.c
index 296175a5dd0d7..bb3aa4b852e7c 100644
--- a/src/time/unix/SDL_systime.c
+++ b/src/time/unix/SDL_systime.c
@@ -27,6 +27,7 @@
#include <langinfo.h>
#include <sys/time.h>
#include <time.h>
+#include <unistd.h>
#if !defined(HAVE_CLOCK_GETTIME) && defined(SDL_PLATFORM_APPLE)
#include <mach/clock.h>
@@ -186,7 +187,23 @@ bool SDL_TimeToDateTime(SDL_Time ticks, SDL_DateTime *dt, bool localTime)
dt->second = tm->tm_sec;
dt->nanosecond = ticks % SDL_NS_PER_SECOND;
dt->day_of_week = tm->tm_wday;
+
+ /* tm_gmtoff wasn't formally standardized until POSIX.1-2024, but practically it has been available on desktop
+ * *nix platforms such as Linux/glibc, FreeBSD, OpenBSD, NetBSD, OSX/macOS, and others since the 1990s.
+ *
+ * The notable exception is Solaris, where the timezone offset must still be retrieved in the strictly POSIX.1-2008
+ * compliant way.
+ */
+#if (_POSIX_VERSION >= 202405L) || (!defined(sun) && !defined(__sun))
dt->utc_offset = (int)tm->tm_gmtoff;
+#else
+ if (localTime) {
+ tzset();
+ dt->utc_offset = (int)timezone;
+ } else {
+ dt->utc_offset = 0;
+ }
+#endif
return true;
}