windows-port iterate

This commit is contained in:
John Kerl 2017-04-08 00:20:18 -04:00
parent 7bcfc91db3
commit 9d3619a8aa
5 changed files with 28 additions and 26 deletions

View file

@ -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
}

View file

@ -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

View file

@ -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);
}

View file

@ -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);

View file

@ -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: