-#ifndef LOCALTIME64_H
-# define LOCALTIME64_H
+#include <time.h>
+#include "time64_config.h"
-/* Configuration. */
-/* Define as appropriate for your system */
-/*
- HAS_GMTIME_R
- Defined if your system has gmtime_r()
+#ifndef TIME64_H
+# define TIME64_H
- HAS_LOCALTIME_R
- Defined if your system has localtime_r()
- HAS_TIMEGM
- Defined if your system has timegm()
+/* Set our custom types */
+typedef INT_64_T Int64;
+typedef Int64 Time64_T;
+typedef I32 Year;
- HAS_TM_TM_GMTOFF
- Defined if your tm struct has a "tm_gmtoff" element.
- HAS_TM_TM_ZONE
- Defined if your tm struct has a "tm_zone" element.
+/* A copy of the tm struct but with a 64 bit year */
+struct TM64 {
+ int tm_sec;
+ int tm_min;
+ int tm_hour;
+ int tm_mday;
+ int tm_mon;
+ Year tm_year;
+ int tm_wday;
+ int tm_yday;
+ int tm_isdst;
- SYSTEM_LOCALTIME_MAX
- SYSTEM_LOCALTIME_MIN
- SYSTEM_GMTIME_MAX
- SYSTEM_GMTIME_MIN
- Maximum and minimum values your system's gmtime() and localtime()
- can handle.
+#ifdef HAS_TM_TM_GMTOFF
+ long tm_gmtoff;
+#endif
- USE_SYSTEM_LOCALTIME
- USE_SYSTEM_GMTIME
- Should we use the system functions if the time is inside their range?
-*/
-#define SYSTEM_LOCALTIME_MAX LOCALTIME_MAX
-#define SYSTEM_LOCALTIME_MIN LOCALTIME_MIN
-#define SYSTEM_GMTIME_MAX GMTIME_MAX
-#define SYSTEM_GMTIME_MIN GMTIME_MIN
+#ifdef HAS_TM_TM_ZONE
+# ifdef __GLIBC__
+ const char *tm_zone;
+# else
+ char *tm_zone;
+# endif
+#endif
+};
-/* It'll be faster */
-#define USE_SYSTEM_LOCALTIME 1
-#define USE_SYSTEM_GMTIME 1
+/* Decide which tm struct to use */
+#ifdef USE_TM64
+#define TM TM64
+#else
+#define TM tm
+#endif
-/* 64 bit types. Set as appropriate for your system. */
-typedef Quad_t Time64_T;
-typedef Quad_t Int64;
-typedef Int64 Year;
-struct tm *gmtime64_r (const Time64_T *, struct tm *);
-struct tm *localtime64_r (const Time64_T *, struct tm *);
-Time64_T timegm64 (struct tm *);
+/* Declare functions */
+static struct TM *S_gmtime64_r (const Time64_T *, struct TM *);
+static struct TM *S_localtime64_r (const Time64_T *, struct TM *);
+static Time64_T S_timegm64 (struct TM *);
-/* Not everyone has gm/localtime_r() */
+/* Not everyone has gm/localtime_r(), provide a replacement */
#ifdef HAS_LOCALTIME_R
-# define LOCALTIME_R(clock, result) localtime_r(clock, result)
+# define LOCALTIME_R(clock, result) (L_R_TZSET localtime_r(clock, result))
#else
-# define LOCALTIME_R(clock, result) fake_localtime_r(clock, result)
+# define LOCALTIME_R(clock, result) (L_R_TZSET S_localtime_r(clock, result))
#endif
#ifdef HAS_GMTIME_R
# define GMTIME_R(clock, result) gmtime_r(clock, result)
#else
-# define GMTIME_R(clock, result) fake_gmtime_r(clock, result)
+# define GMTIME_R(clock, result) S_gmtime_r(clock, result)
#endif
#endif