mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-05 19:08:12 +00:00
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 7b93a744c8
)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user