%{#
#include "libc/CATS/time.cats"
%}
staload TYPES = "libc/sys/SATS/types.sats"
typedef tm_struct =
$extype_struct "ats_tm_struct_type" of {
tm_sec= int
, tm_min= int
, tm_hour= int
, tm_mday= int
, tm_mon= int
, tm_year= int
, tm_wday= int
, tm_yday= int
, tm_isdst= int
}
typedef time_t = $TYPES.time_t
fun lint_of_time (t: time_t):<> lint = "atslib_lint_of_time"
overload lint_of with lint_of_time
fun double_of_time (t: time_t):<> double = "atslib_double_of_time"
overload double_of with double_of_time
fun difftime
(finish: time_t, start: time_t):<> double = "#atslib_difftime"
fun tm_get_sec
(tm: &tm_struct):<> int = "atslib_tm_get_sec"
fun tm_get_min
(tm: &tm_struct):<> int = "atslib_tm_get_min"
fun tm_get_hour
(tm: &tm_struct):<> int = "atslib_tm_get_hour"
fun tm_get_mday
(tm: &tm_struct):<> int = "atslib_tm_get_mday"
fun tm_get_mon
(tm: &tm_struct):<> int = "atslib_tm_get_mon"
fun tm_get_year
(tm: &tm_struct):<> int = "atslib_tm_get_year"
fun tm_get_wday
(tm: &tm_struct):<> int = "atslib_tm_get_wday"
fun tm_get_yday
(tm: &tm_struct):<> int = "atslib_tm_get_yday"
fun tm_get_isdst
(tm: &tm_struct):<> int = "atslib_tm_get_isdst"
symintr time
fun time_get (): time_t = "atslib_time_get"
overload time with time_get
fun time_get_and_set (p: &time_t? >> opt (time_t, b)): #[b:bool] bool (b)
= "atslib_time_get_and_set" overload time with time_get_and_set
fun ctime (t: &time_t):<!ref>
[l:addr] (strptr l -<lin,prf> void | strptr l) = "#atslib_ctime"
#define CTIME_BUFLEN 26
dataview ctime_v (m:int, l:addr, addr) =
| {l>null} ctime_v_succ (m, l, l) of strbuf (m, CTIME_BUFLEN - 1) @ l
| ctime_v_fail (m, l, null) of b0ytes (m) @ l
fun ctime_r {m:int | m >= CTIME_BUFLEN} {l:addr} (
pf: ! b0ytes (m) @ l >> ctime_v (m, l, l1)
| t: &time_t, p_buf: ptr l
) :<> #[l1:addr] ptr l1 = "#atslib_ctime_r"
fun localtime (time: &time_t):<!ref>
[l:addr] (ptroutopt (tm_struct, l) | ptr l) = "#atslib_localtime"
fun localtime_r (
time: &time_t, tm: &tm_struct? >> opt (tm_struct, l > null)
) :<> #[l:addr] ptr l = "#atslib_localtime_r"
fun gmtime (time: &time_t):<!ref>
[l:addr] (ptroutopt (tm_struct, l) | ptr l) = "#atslib_gmtime"
fun gmtime_r (
time: &time_t, tm: &tm_struct? >> opt (tm_struct, l > null)
) :<> #[l:addr] ptr l = "#atslib_gmtime_r"
fun mktime (tm: &tm_struct): time_t = "#atslib_mktime"
fun asctime (tm: &tm_struct):<!ref>
[l:addr] (strptr l -<lin,prf> void | strptr l) = "#atslib_asctime"
fun strftime {m:pos} {l:addr} (
pf: !b0ytes m @ l >> strbuf (m, n) @ l
| p: ptr l, m: size_t m, fmt: string, tm: &tm_struct
) :<> #[n:nat | n < m] size_t n
= "#atslib_strftime"
fun strptime (
str: string
, fmt: string
, tm: &tm_struct? >> opt (tm_struct, l > null)
) : #[l:addr] ptr l = "#atslib_strptime"
fun tzsset ():<!ref> void = "#atslib_tzset"
typedef clock_t = $TYPES.clock_t
macdef CLOCKS_PER_SEC = $extval (clock_t, "CLOCKS_PER_SEC")
fun lint_of_clock (c: clock_t):<> lint = "atslib_lint_of_clock"
overload lint_of with lint_of_clock
fun double_of_clock (c: clock_t):<> double = "atslib_double_of_clock"
overload double_of with double_of_clock
fun clock (): clock_t = "#atslib_clock"
typedef timespec_struct =
$extype_struct "ats_timespec_type" of {
tv_sec= time_t
, tv_nsec= lint
} typedef timespec = timespec_struct
fun nanosleep (
nsec: ×pec, rem: ×pec? >> opt (timespec, i==0)
) : #[i:int | i <= 0] int(i) = "#atslib_nanosleep"
fun nanosleep_null (nsec: ×pec): int = "#atslib_nanosleep_null"
typedef clockid_t = $TYPES.clockid_t
macdef CLOCK_REALTIME = $extval (clockid_t, "CLOCK_REALTIME")
macdef CLOCK_MONOTONIC = $extval (clockid_t, "CLOCK_MONOTONIC")
fun clock_gettime (
id: clockid_t
, tp: ×pec? >> opt (timespec, i==0)
) : #[i:int | i <= 0] int(i) = "#atslib_clock_gettime"
fun clock_getres (
id: clockid_t
, tp: ×pec? >> opt (timespec, i==0)
) : #[i:int | i <= 0] int(i) = "#atslib_clock_getres"
fun clock_settime (id: clockid_t, tp: ×pec): int = "#atslib_clock_settime"