aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compat.h33
-rw-r--r--src/date.h9
-rw-r--r--src/polyfill.c2
-rw-r--r--src/polyfill.h28
-rw-r--r--src/time.c1
-rw-r--r--src/tm.c1
6 files changed, 37 insertions, 37 deletions
diff --git a/src/compat.h b/src/compat.h
new file mode 100644
index 0000000..a13c3ed
--- /dev/null
+++ b/src/compat.h
@@ -0,0 +1,33 @@
+#pragma once
+#include <time.h>
+
+// GNU-ish systems require this to expose tm_gmtoff and tm_zone
+// this is important because of how we detect their existence
+#define _GNU_SOURCE 1
+
+// timegm
+#ifdef _MSC_VER
+#define timegm _mkgmtime
+#else
+// since tm is a pointer, it should be ABI-compatible even if the true type is mismatched
+time_t timegm(struct tm *tm);
+#endif
+
+// ===
+
+// public domain code from
+// https://github.com/eggert/tz.git
+
+/* Infer TM_ZONE on systems where this information is known, but suppress
+ guessing if NO_TM_ZONE is defined. Similarly for TM_GMTOFF. */
+#if (defined __GLIBC__ \
+ || defined __tm_zone /* musl */ \
+ || defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ \
+ || (defined __APPLE__ && defined __MACH__))
+# if !defined TM_GMTOFF && !defined NO_TM_GMTOFF
+# define TM_GMTOFF tm_gmtoff
+# endif
+# if !defined TM_ZONE && !defined NO_TM_ZONE
+# define TM_ZONE tm_zone
+# endif
+#endif
diff --git a/src/date.h b/src/date.h
index bd9cf27..61f9173 100644
--- a/src/date.h
+++ b/src/date.h
@@ -1,13 +1,10 @@
#pragma once
-// compatibility flags
-
-// GNU-ish systems require this to expose tm_gmtoff and tm_zone
-// this is important because of how we detect their existence
-#define _GNU_SOURCE 1
+#include "compat.h"
+#include "polyfill.h"
+// technically included above, here for posterity
#include <janet.h>
#include <time.h>
-#include "polyfill.h"
// util.c
JanetBuffer *strftime_buffer(const char *format, const struct tm *tm, JanetBuffer *buffer);
diff --git a/src/polyfill.c b/src/polyfill.c
index 0d99916..cf8a2fb 100644
--- a/src/polyfill.c
+++ b/src/polyfill.c
@@ -1,4 +1,4 @@
-#include "date.h"
+#include "polyfill.h"
#ifdef POLYFILL_CBYTES
const char* janet_getcbytes(const Janet *argv, int32_t n) {
diff --git a/src/polyfill.h b/src/polyfill.h
index 70ea4f5..bf4c5c9 100644
--- a/src/polyfill.h
+++ b/src/polyfill.h
@@ -1,6 +1,5 @@
#pragma once
#include <janet.h>
-#include <time.h>
#if JANET_VERSION_MAJOR < 2 && JANET_VERSION_MINOR < 28
#define POLYFILL_CBYTES
@@ -20,30 +19,3 @@ const char *janet_optcbytes(const Janet *argv, int32_t argc, int32_t n, const ch
Janet CNAME (int32_t argc, Janet *argv)
#endif // !defined(JANET_NO_SOURCEMAPS)
#endif // JANET_VERSION_MAJOR < 2 && JANET_VERSION_MINOR < 28
-
-// timegm
-#ifdef _MSC_VER
-#define timegm _mkgmtime
-#else
-// since tm is a pointer, it should be ABI-compatible even if the true type is mismatched
-time_t timegm(struct tm *tm);
-#endif
-
-// ===
-
-// public domain code from
-// https://github.com/eggert/tz.git
-
-/* Infer TM_ZONE on systems where this information is known, but suppress
- guessing if NO_TM_ZONE is defined. Similarly for TM_GMTOFF. */
-#if (defined __GLIBC__ \
- || defined __tm_zone /* musl */ \
- || defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ \
- || (defined __APPLE__ && defined __MACH__))
-# if !defined TM_GMTOFF && !defined NO_TM_GMTOFF
-# define TM_GMTOFF tm_gmtoff
-# endif
-# if !defined TM_ZONE && !defined NO_TM_ZONE
-# define TM_ZONE tm_zone
-# endif
-#endif
diff --git a/src/time.c b/src/time.c
index 8031e44..f9bda70 100644
--- a/src/time.c
+++ b/src/time.c
@@ -1,5 +1,4 @@
#include "date.h"
-#include "janet.h"
// wrappers around time_t
diff --git a/src/tm.c b/src/tm.c
index c15c22a..f04e9a9 100644
--- a/src/tm.c
+++ b/src/tm.c
@@ -1,5 +1,4 @@
#include "date.h"
-#include "janet.h"
// wrappers around struct tm