From 9d3619a8aadbfe23171e0e6c8d72048fc5e2fcfc Mon Sep 17 00:00:00 2001 From: John Kerl Date: Sat, 8 Apr 2017 00:20:18 -0400 Subject: [PATCH] windows-port iterate --- c/lib/mlr_arch.c | 23 +++++++++++++++++++++++ c/lib/mlr_arch.h | 1 + c/lib/mlrdatetime.c | 24 +----------------------- c/lib/mlrdatetime.h | 3 --- c/todo.txt | 3 +++ 5 files changed, 28 insertions(+), 26 deletions(-) diff --git a/c/lib/mlr_arch.c b/c/lib/mlr_arch.c index 63993472f..c0158048e 100644 --- a/c/lib/mlr_arch.c +++ b/c/lib/mlr_arch.c @@ -37,3 +37,26 @@ char *mlr_arch_strptime(const char *s, const char *format, struct tm *ptm) { return strptime(s, format, ptm); #endif } + +// ---------------------------------------------------------------- +// See the GNU timegm manpage -- this is what it does. +time_t mlr_arch_timegm(struct tm* ptm) { +#ifdef MLR_ON_MSYS2 + return _mkgmtime(ptm); +#else + time_t ret; + char* tz; + + tz = getenv("TZ"); + mlr_arch_setenv("TZ", "GMT0"); + tzset(); + ret = mktime(ptm); + if (tz) { + mlr_arch_setenv("TZ", tz); + } else { + mlr_arch_unsetenv("TZ"); + } + tzset(); + return ret; +#endif +} diff --git a/c/lib/mlr_arch.h b/c/lib/mlr_arch.h index 97eaf5c8b..34ef16473 100644 --- a/c/lib/mlr_arch.h +++ b/c/lib/mlr_arch.h @@ -27,5 +27,6 @@ int mlr_arch_setenv(const char *name, const char *value); int mlr_arch_unsetenv(const char *name); char *mlr_arch_strptime(const char *s, const char *format, struct tm *ptm); +time_t mlr_arch_timegm(struct tm* ptm); #endif // MLR_ARCH_H diff --git a/c/lib/mlrdatetime.c b/c/lib/mlrdatetime.c index 1294c7d0b..4e432f1dd 100644 --- a/c/lib/mlrdatetime.c +++ b/c/lib/mlrdatetime.c @@ -8,9 +8,6 @@ #include "lib/mlrutil.h" #include "lib/mlrdatetime.h" -// For some Linux distros, in spite of including time.h: -char *strptime(const char *s, const char *format, struct tm *ptm); - // ---------------------------------------------------------------- // seconds since the epoch double get_systime() { @@ -19,25 +16,6 @@ double get_systime() { return (double)tv.tv_sec + (double)tv.tv_usec * 1e-6; } -// ---------------------------------------------------------------- -// See the GNU timegm manpage -- this is what it does. -time_t mlr_timegm(struct tm* ptm) { - time_t ret; - char* tz; - - tz = getenv("TZ"); - mlr_arch_setenv("TZ", "GMT0"); - tzset(); - ret = mktime(ptm); - if (tz) { - mlr_arch_setenv("TZ", tz); - } else { - mlr_arch_unsetenv("TZ"); - } - tzset(); - return ret; -} - // ---------------------------------------------------------------- #define NZBUFLEN 63 char* mlr_alloc_time_string_from_seconds(time_t seconds, char* format) { @@ -64,5 +42,5 @@ time_t mlr_seconds_from_time_string(char* string, char* format) { exit(1); } MLR_INTERNAL_CODING_ERROR_IF(*retval != 0); // Parseable input followed by non-parseable - return mlr_timegm(&tm); + return mlr_arch_timegm(&tm); } diff --git a/c/lib/mlrdatetime.h b/c/lib/mlrdatetime.h index 4dcfd36b5..5b9c655de 100644 --- a/c/lib/mlrdatetime.h +++ b/c/lib/mlrdatetime.h @@ -8,9 +8,6 @@ double get_systime(); -// portable timegm replacement -time_t mlr_timegm (struct tm *ptm); - char* mlr_alloc_time_string_from_seconds(time_t seconds, char* format); time_t mlr_seconds_from_time_string(char* string, char* format); diff --git a/c/todo.txt b/c/todo.txt index f308f92a0..6f1634357 100644 --- a/c/todo.txt +++ b/c/todo.txt @@ -5,6 +5,9 @@ BUGFIXES ! neaten vg.out ! ! synctool -4/-6 +! $ mlr --from s put "'$t=4'" + Segmentation fault: 11 + ================================================================ 5.0.0 POST-RELEASE TO DO: