summaryrefslogtreecommitdiffstats
path: root/src/time64_limits.h
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2016-09-19 03:10:04 +0200
committerGravatar Nikias Bassen2016-09-19 03:10:04 +0200
commit8d34de3078469aba636846a15bad08198f66fdc8 (patch)
treedb97f8ccb45f35f28348b7e2bffc070b87297089 /src/time64_limits.h
parent912cb45928f03355ca162a2f1286ca49eb58155c (diff)
downloadlibplist-8d34de3078469aba636846a15bad08198f66fdc8.tar.gz
libplist-8d34de3078469aba636846a15bad08198f66fdc8.tar.bz2
Use time64 implementation by Michael G Schwern to extend allowed date/time range
The main benefit of this is to allow date/time values outside of the 32bit time_t range which is very important on 32bit platforms. But there are also some other issues that will be fixed with this, for example on macOS, mktime() will not work for dates < 1902 despite time_t being 64bit. In the same run this commit will also use a reentrant version of gmtime64_r that should help in multithreaded scenarios. Original code taken from: https://github.com/evalEmpire/y2038
Diffstat (limited to 'src/time64_limits.h')
-rw-r--r--src/time64_limits.h95
1 files changed, 95 insertions, 0 deletions
diff --git a/src/time64_limits.h b/src/time64_limits.h
new file mode 100644
index 0000000..91079af
--- /dev/null
+++ b/src/time64_limits.h
@@ -0,0 +1,95 @@
+/*
+ Maximum and minimum inputs your system's respective time functions
+ can correctly handle. time64.h will use your system functions if
+ the input falls inside these ranges and corresponding USE_SYSTEM_*
+ constant is defined.
+*/
+
+#ifndef TIME64_LIMITS_H
+#define TIME64_LIMITS_H
+
+/* Max/min for localtime() */
+#define SYSTEM_LOCALTIME_MAX 2147483647
+#define SYSTEM_LOCALTIME_MIN -2147483647-1
+
+/* Max/min for gmtime() */
+#define SYSTEM_GMTIME_MAX 2147483647
+#define SYSTEM_GMTIME_MIN -2147483647-1
+
+/* Max/min for mktime() */
+static const struct tm SYSTEM_MKTIME_MAX = {
+ 7,
+ 14,
+ 19,
+ 18,
+ 0,
+ 138,
+ 1,
+ 17,
+ 0
+#ifdef HAVE_TM_TM_GMTOFF
+ ,-28800
+#endif
+#ifdef HAVE_TM_TM_ZONE
+ ,(char*)"PST"
+#endif
+};
+
+static const struct tm SYSTEM_MKTIME_MIN = {
+ 52,
+ 45,
+ 12,
+ 13,
+ 11,
+ 1,
+ 5,
+ 346,
+ 0
+#ifdef HAVE_TM_TM_GMTOFF
+ ,-28800
+#endif
+#ifdef HAVE_TM_TM_ZONE
+ ,(char*)"PST"
+#endif
+};
+
+/* Max/min for timegm() */
+#ifdef HAVE_TIMEGM
+static const struct tm SYSTEM_TIMEGM_MAX = {
+ 7,
+ 14,
+ 3,
+ 19,
+ 0,
+ 138,
+ 2,
+ 18,
+ 0
+ #ifdef HAVE_TM_TM_GMTOFF
+ ,0
+ #endif
+ #ifdef HAVE_TM_TM_ZONE
+ ,(char*)"UTC"
+ #endif
+};
+
+static const struct tm SYSTEM_TIMEGM_MIN = {
+ 52,
+ 45,
+ 20,
+ 13,
+ 11,
+ 1,
+ 5,
+ 346,
+ 0
+ #ifdef HAVE_TM_TM_GMTOFF
+ ,0
+ #endif
+ #ifdef HAVE_TM_TM_ZONE
+ ,(char*)"UTC"
+ #endif
+};
+#endif /* HAVE_TIMEGM */
+
+#endif /* TIME64_LIMITS_H */