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