X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=psi.d%2Ftime.psi;h=89074341ce0f9f7b35c2753a8433c9749c08047a;hp=e01bd1be6c037a5bded943b5e3bb1cc562dfe7da;hb=601e13c0743234c53a62e68fc89f122069123c15;hpb=b4508f6b917660970f887894a6aaed6c220a2c72 diff --git a/psi.d/time.psi b/psi.d/time.psi index e01bd1b..8907434 100644 --- a/psi.d/time.psi +++ b/psi.d/time.psi @@ -1,14 +1,19 @@ +#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 *tv, struct timezone *tz); +// extern int gettimeofday(struct timeval *tp, struct timezone *tz); function psi\gettimeofday(array &$tv = NULL, array &$tz = NULL) : int { - let tv = calloc(1, struct timeval); - let tz = calloc(1, struct timezone); - return to_int(gettimeofday); - set $tv = to_array(*tv, + let tp = calloc(1, sizeof(struct timeval)); + let tz = calloc(1, sizeof(struct timezone)); + 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, @@ -16,23 +21,43 @@ function psi\gettimeofday(array &$tv = NULL, array &$tz = NULL) : int { to_int(tz_dsttime)); } -extern char *asctime(struct tm *tm); -function psi\asctime(array $tm = NULL) : string { - let tm = arrval($tm); - return to_string(asctime); +// extern char *asctime(struct tm *tm); +function psi\asctime(array $tm) : string { + let tm = &arrval($tm, + intval($tm_sec), + intval($tm_min), + intval($tm_hour), + intval($tm_mday), + intval($tm_mon), + intval($tm_year), + intval($tm_wday), + intval($tm_yday), + intval($tm_isdst) + ); + return asctime(tm) as to_string(asctime); } -extern char *asctime_r(struct tm *tm, char *buf); -function psi\asctime_r(array $tm = NULL) : string { - let tm = arrval($tm); - let buf = calloc(32, char); - return to_string(asctime_r); +// extern char *asctime_r(struct tm *tm, char *buf); +function psi\asctime_r(array $tm) : string { + let tm = &arrval($tm, + intval($tm_sec), + intval($tm_min), + intval($tm_hour), + intval($tm_mday), + intval($tm_mon), + intval($tm_year), + intval($tm_wday), + intval($tm_yday), + intval($tm_isdst) + ); + let buf = calloc(32, sizeof(char)); + return asctime_r(tm, buf) as to_string(asctime_r); } -extern struct tm *gmtime(time_t *tp); +// extern struct tm *gmtime(time_t *t); function psi\gmtime(int $ts) : array { - let tp = &intval($ts); - return to_array(*gmtime, + let t = &intval($ts); + return gmtime(t) as to_array(*gmtime, to_int(tm_sec), to_int(tm_min), to_int(tm_hour), @@ -45,11 +70,11 @@ function psi\gmtime(int $ts) : array { ); } -extern struct tm *gmtime_r(time_t *tp, struct tm *buf); +// extern struct tm *gmtime_r(time_t *t, struct tm *buf); function psi\gmtime_r(int $ts) : array { - let tp = &intval($ts); - let buf = calloc(1, struct tm); - return to_array(*gmtime_r, + let t = &intval($ts); + 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), @@ -62,21 +87,25 @@ function psi\gmtime_r(int $ts) : array { ); } -extern int nanosleep(struct timespec *rqtp, struct timespec *rmtp); +// extern int nanosleep(struct timespec *rqts, struct timespec *rmts); function psi\nanosleep(array $rq = NULL, array &$rm = NULL) : int { - let rqtp = arrval($rq); - let rmtp = calloc(1, struct timespec); - return to_int(nanosleep); - set $rm = to_array(*rmtp, + let rqts = &arrval($rq, + intval($tv_sec), + intval($tv_nsec) + ); + 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); + +// extern clock_t times(struct tms *buf); function psi\times(array &$tms = NULL) : int { - let buf = calloc(1, 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),