X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;ds=sidebyside;f=psi.d%2Ftime.psi;h=9bf08515a1a3fccb4ed3d09f62025720a2098030;hb=cacb11fac1eb3f21eb55365cbff3c5e223cc7092;hp=25bc4e86f8d1efbc53eaefc1fa770586920059cb;hpb=9bcb1df0786a8193d65949c857baaba2f4296e84;p=m6w6%2Fext-psi diff --git a/psi.d/time.psi b/psi.d/time.psi index 25bc4e8..9bf0851 100644 --- a/psi.d/time.psi +++ b/psi.d/time.psi @@ -1,20 +1,25 @@ +#ifdef __linux__ /* old, anyway */ +#pragma lib "rt" +#endif + +#include +#include +#include + // extern time_t time(time_t *t); function psi\time() : int { let t = NULL; - return to_int(time); + return time(t) as to_int(time); } // extern int gettimeofday(struct timeval *tp, struct timezone *tz); -function psi\gettimeofday(array &$tv = NULL, array &$tz = NULL) : int { - let tp = calloc(1, psi\SIZEOF_STRUCT_TIMEVAL); - let tz = calloc(1, psi\SIZEOF_STRUCT_TIMEZONE); - return to_int(gettimeofday); +function psi\gettimeofday(array &$tv = NULL) : int { + let tp = calloc(1, sizeof(struct timeval)); + let tz = NULL; + return gettimeofday(tp, tz) as to_int(gettimeofday); set $tv = to_array(*tp, to_int(tv_sec), to_int(tv_usec)); - set $tz = to_array(*tz, - to_int(tz_minuteswest), - to_int(tz_dsttime)); } // extern char *asctime(struct tm *tm); @@ -30,7 +35,7 @@ function psi\asctime(array $tm) : string { intval($tm_yday), intval($tm_isdst) ); - return to_string(asctime); + return asctime(tm) as to_string(asctime); } // extern char *asctime_r(struct tm *tm, char *buf); @@ -46,14 +51,14 @@ function psi\asctime_r(array $tm) : string { intval($tm_yday), intval($tm_isdst) ); - let buf = calloc(32, psi\SIZEOF_CHAR); - return to_string(asctime_r); + let buf = calloc(32, sizeof(char)); + return asctime_r(tm, buf) as to_string(asctime_r); } // extern struct tm *gmtime(time_t *t); function psi\gmtime(int $ts) : array { let t = &intval($ts); - return to_array(*gmtime, + return gmtime(t) as to_array(*gmtime, to_int(tm_sec), to_int(tm_min), to_int(tm_hour), @@ -69,8 +74,8 @@ function psi\gmtime(int $ts) : array { // extern struct tm *gmtime_r(time_t *t, struct tm *buf); function psi\gmtime_r(int $ts) : array { let t = &intval($ts); - let buf = calloc(1, psi\SIZEOF_STRUCT_TM); - return to_array(*gmtime_r, + let buf = calloc(1, sizeof(struct tm)); + return gmtime_r(t, buf) as to_array(*gmtime_r, to_int(tm_sec), to_int(tm_min), to_int(tm_hour), @@ -89,18 +94,19 @@ function psi\nanosleep(array $rq = NULL, array &$rm = NULL) : int { intval($tv_sec), intval($tv_nsec) ); - let rmts = calloc(1, psi\SIZEOF_STRUCT_TIMESPEC); - return to_int(nanosleep); + let rmts = calloc(1, sizeof(struct timespec)); + return nanosleep(rqts, rmts) as to_int(nanosleep); set $rm = to_array(*rmts, to_int(tv_sec), to_int(tv_nsec) ); } + // extern clock_t times(struct tms *buf); function psi\times(array &$tms = NULL) : int { - let buf = calloc(1, psi\SIZEOF_STRUCT_TMS); - return to_int(times); + let buf = calloc(1, sizeof(struct tms)); + return times(buf) as to_int(times); set $tms = to_array(*buf, to_int(tms_utime), to_int(tms_stime), @@ -108,3 +114,12 @@ function psi\times(array &$tms = NULL) : int { to_int(tms_cstime) ); } + + +function psi\tzset() : void { + return tzset() as void(tzset); +} + +function psi\tzname() : array { + return tzname_get() as to_array(*tzname_get, 2, to_string(*tzname_get)); +}