X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=psi.d%2Ftime.psi;h=25bc4e86f8d1efbc53eaefc1fa770586920059cb;hp=a8082c6456c679e76d9c02a4c3fa39399b6821e0;hb=3ef8c66ab1300801bcdb15b43f9f28e77b6487b6;hpb=4b5ceb304b924c50eaf8263ad394493ff806fed4 diff --git a/psi.d/time.psi b/psi.d/time.psi index a8082c6..25bc4e8 100644 --- a/psi.d/time.psi +++ b/psi.d/time.psi @@ -1,3 +1,4 @@ +// extern time_t time(time_t *t); function psi\time() : int { let t = NULL; return to_int(time); @@ -5,8 +6,8 @@ function psi\time() : int { // extern int gettimeofday(struct timeval *tp, struct timezone *tz); function psi\gettimeofday(array &$tv = NULL, array &$tz = NULL) : int { - let tp = calloc(1, struct timeval); - let tz = calloc(1, struct timezone); + let tp = calloc(1, psi\SIZEOF_STRUCT_TIMEVAL); + let tz = calloc(1, psi\SIZEOF_STRUCT_TIMEZONE); return to_int(gettimeofday); set $tv = to_array(*tp, to_int(tv_sec), @@ -17,15 +18,35 @@ 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); +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 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); +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); } @@ -48,7 +69,7 @@ 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, struct tm); + let buf = calloc(1, psi\SIZEOF_STRUCT_TM); return to_array(*gmtime_r, to_int(tm_sec), to_int(tm_min), @@ -64,8 +85,11 @@ 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 rmts = calloc(1, struct timespec); + let rqts = &arrval($rq, + intval($tv_sec), + intval($tv_nsec) + ); + let rmts = calloc(1, psi\SIZEOF_STRUCT_TIMESPEC); return to_int(nanosleep); set $rm = to_array(*rmts, to_int(tv_sec), @@ -75,7 +99,7 @@ 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, struct tms); + let buf = calloc(1, psi\SIZEOF_STRUCT_TMS); return to_int(times); set $tms = to_array(*buf, to_int(tms_utime),