diff options
Diffstat (limited to 'otherlibs/unix/gmtime.c')
-rw-r--r-- | otherlibs/unix/gmtime.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/otherlibs/unix/gmtime.c b/otherlibs/unix/gmtime.c index d7c251c54..0a101b5c5 100644 --- a/otherlibs/unix/gmtime.c +++ b/otherlibs/unix/gmtime.c @@ -13,6 +13,7 @@ #include <mlvalues.h> #include <alloc.h> +#include <memory.h> #include "unix.h" #include <time.h> @@ -48,3 +49,37 @@ value unix_localtime(t) /* ML */ clock = Long_val(t); return alloc_tm(localtime(&clock)); } + +#ifdef HAS_MKTIME + +value unix_mktime(t) /* ML */ + value t; +{ + struct tm tm; + time_t clock; + value res; + Push_roots(r, 1); + + tm.tm_sec = Int_val(Field(t, 0)); + tm.tm_min = Int_val(Field(t, 1)); + tm.tm_hour = Int_val(Field(t, 2)); + tm.tm_mday = Int_val(Field(t, 3)); + tm.tm_mon = Int_val(Field(t, 4)); + tm.tm_year = Int_val(Field(t, 5)); + tm.tm_wday = Int_val(Field(t, 6)); + tm.tm_yday = Int_val(Field(t, 7)); + tm.tm_isdst = Bool_val(Field(t, 8)); + clock = mktime(&tm); + r[0] = alloc_tm(&tm); + res = alloc_tuple(2); + Field(res, 0) = Val_long(clock); + Field(res, 1) = r[0]; + Pop_roots(); + return res; +} + +#else + +value unix_mktime() { invalid_argument("mktime not implemented"); } + +#endif |