ff81e932c1c8bc0f73c8cb78604942d9c6d91c94
[m6w6/ext-psi] / psi.d / time.psi
1 function psi\time() : int {
2 let t = NULL;
3 return to_int(time);
4 }
5
6 // extern int gettimeofday(struct timeval *tp, struct timezone *tz);
7 function psi\gettimeofday(array &$tv = NULL, array &$tz = NULL) : int {
8 let tp = calloc(1, psi\SIZEOF_STRUCT_TIMEVAL);
9 let tz = calloc(1, psi\SIZEOF_STRUCT_TIMEZONE);
10 return to_int(gettimeofday);
11 set $tv = to_array(*tp,
12 to_int(tv_sec),
13 to_int(tv_usec));
14 set $tz = to_array(*tz,
15 to_int(tz_minuteswest),
16 to_int(tz_dsttime));
17 }
18
19 // extern char *asctime(struct tm *tm);
20 function psi\asctime(array $tm = NULL) : string {
21 let tm = arrval($tm);
22 return to_string(asctime);
23 }
24
25 // extern char *asctime_r(struct tm *tm, char *buf);
26 function psi\asctime_r(array $tm = NULL) : string {
27 let tm = arrval($tm);
28 let buf = calloc(32, psi\SIZEOF_CHAR);
29 return to_string(asctime_r);
30 }
31
32 // extern struct tm *gmtime(time_t *t);
33 function psi\gmtime(int $ts) : array {
34 let t = &intval($ts);
35 return to_array(*gmtime,
36 to_int(tm_sec),
37 to_int(tm_min),
38 to_int(tm_hour),
39 to_int(tm_mday),
40 to_int(tm_mon),
41 to_int(tm_year),
42 to_int(tm_wday),
43 to_int(tm_yday),
44 to_int(tm_isdst)
45 );
46 }
47
48 // extern struct tm *gmtime_r(time_t *t, struct tm *buf);
49 function psi\gmtime_r(int $ts) : array {
50 let t = &intval($ts);
51 let buf = calloc(1, psi\SIZEOF_STRUCT_TM);
52 return to_array(*gmtime_r,
53 to_int(tm_sec),
54 to_int(tm_min),
55 to_int(tm_hour),
56 to_int(tm_mday),
57 to_int(tm_mon),
58 to_int(tm_year),
59 to_int(tm_wday),
60 to_int(tm_yday),
61 to_int(tm_isdst)
62 );
63 }
64
65 // extern int nanosleep(struct timespec *rqts, struct timespec *rmts);
66 function psi\nanosleep(array $rq = NULL, array &$rm = NULL) : int {
67 let rqts = arrval($rq);
68 let rmts = calloc(1, psi\SIZEOF_STRUCT_TIMESPEC);
69 return to_int(nanosleep);
70 set $rm = to_array(*rmts,
71 to_int(tv_sec),
72 to_int(tv_nsec)
73 );
74 }
75
76 // extern clock_t times(struct tms *buf);
77 function psi\times(array &$tms = NULL) : int {
78 let buf = calloc(1, psi\SIZEOF_STRUCT_TMS);
79 return to_int(times);
80 set $tms = to_array(buf,
81 to_int(tms_utime),
82 to_int(tms_stime),
83 to_int(tms_cutime),
84 to_int(tms_cstime)
85 );
86 }