diff options
| -rw-r--r-- | src/compat.h | 33 | ||||
| -rw-r--r-- | src/date.h | 9 | ||||
| -rw-r--r-- | src/polyfill.c | 2 | ||||
| -rw-r--r-- | src/polyfill.h | 28 | ||||
| -rw-r--r-- | src/time.c | 1 | ||||
| -rw-r--r-- | src/tm.c | 1 |
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 @@ -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 @@ -1,5 +1,4 @@ #include "date.h" -#include "janet.h" // wrappers around time_t @@ -1,5 +1,4 @@ #include "date.h" -#include "janet.h" // wrappers around struct tm |
