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