X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=psi.d%2Ftime.psi;h=7fb3cb905a981203d5671aaf79a99b0d5c2ca63b;hp=ff81e932c1c8bc0f73c8cb78604942d9c6d91c94;hb=b78637d9020222f1032349f231c0dc84a69797bc;hpb=cfebc76ed7426836f21296cca9a14b422bfa04cf diff --git a/psi.d/time.psi b/psi.d/time.psi index ff81e93..7fb3cb9 100644 --- a/psi.d/time.psi +++ b/psi.d/time.psi @@ -1,13 +1,14 @@ +// 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); + return gettimeofday(tp, tz) as to_int(gettimeofday); set $tv = to_array(*tp, to_int(tv_sec), to_int(tv_usec)); @@ -17,22 +18,42 @@ function psi\gettimeofday(array &$tv = NULL, array &$tz = NULL) : int { } // extern char *asctime(struct tm *tm); -function psi\asctime(array $tm = NULL) : string { - let tm = arrval($tm); - return to_string(asctime); +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); +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, psi\SIZEOF_CHAR); - return to_string(asctime_r); + 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), @@ -49,7 +70,7 @@ function psi\gmtime(int $ts) : array { function psi\gmtime_r(int $ts) : array { let t = &intval($ts); let buf = calloc(1, psi\SIZEOF_STRUCT_TM); - return to_array(*gmtime_r, + return gmtime_r(t, buf) as to_array(*gmtime_r, to_int(tm_sec), to_int(tm_min), to_int(tm_hour), @@ -64,9 +85,12 @@ function psi\gmtime_r(int $ts) : array { // extern int nanosleep(struct timespec *rqts, struct timespec *rmts); function psi\nanosleep(array $rq = NULL, array &$rm = NULL) : int { - let rqts = arrval($rq); + let rqts = &arrval($rq, + intval($tv_sec), + intval($tv_nsec) + ); let rmts = calloc(1, psi\SIZEOF_STRUCT_TIMESPEC); - return to_int(nanosleep); + return nanosleep(rqts, rmts) as to_int(nanosleep); set $rm = to_array(*rmts, to_int(tv_sec), to_int(tv_nsec) @@ -76,8 +100,8 @@ function psi\nanosleep(array $rq = NULL, array &$rm = NULL) : int { // 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); - set $tms = to_array(buf, + return times(buf) as to_int(times); + set $tms = to_array(*buf, to_int(tms_utime), to_int(tms_stime), to_int(tms_cutime),