/usr/lib/ats-anairiats-0.2.11/libc/SATS/time.sats is in ats-lang-anairiats 0.2.11-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | (***********************************************************************)
(* *)
(* Applied Type System *)
(* *)
(* Hongwei Xi *)
(* *)
(***********************************************************************)
(*
** ATS - Unleashing the Potential of Types!
** Copyright (C) 2002-2010 Hongwei Xi, Boston University
** All rights reserved
**
** ATS is free software; you can redistribute it and/or modify it under
** the terms of the GNU General Public License as published by the Free
** Software Foundation; either version 2.1, or (at your option) any later
** version.
**
** ATS is distributed in the hope that it will be useful, but WITHOUT ANY
** WARRANTY; without even the implied warranty of MERCHANTABILITY or
** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
** for more details.
**
** You should have received a copy of the GNU General Public License
** along with ATS; see the file COPYING. If not, please write to the
** Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
** 02110-1301, USA.
*)
(* ****** ****** *)
(* author: Hongwei Xi (hwxi AT cs DOT bu DOT edu) *)
(* ****** ****** *)
%{#
#include "libc/CATS/time.cats"
%} // end of [%{#]
(* ****** ****** *)
staload TYPES = "libc/sys/SATS/types.sats"
(* ****** ****** *)
typedef tm_struct =
$extype_struct "ats_tm_struct_type" of {
tm_sec= int (* seconds *)
, tm_min= int (* minutes *)
, tm_hour= int (* hours *)
, tm_mday= int (* day of the month *)
, tm_mon= int (* month *)
, tm_year= int (* year *)
, tm_wday= int (* day of the week *)
, tm_yday= int (* day in the year *)
, tm_isdst= int (* daylight saving time *)
} // end of [tm_struct]
(* ****** ****** *)
typedef time_t = $TYPES.time_t
//
// HX: these are implemented in libc/sys/CATS/types.cats
//
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
= "mac#atslib_difftime"
// end of [difftime]
(* ****** ****** *)
(*
** HX (2010-01-15):
** These functions are now kept for backward compatibility
*)
fun tm_get_sec
(tm: &READ(tm_struct)):<> int = "atslib_tm_get_sec"
fun tm_get_min
(tm: &READ(tm_struct)):<> int = "atslib_tm_get_min"
fun tm_get_hour
(tm: &READ(tm_struct)):<> int = "atslib_tm_get_hour"
fun tm_get_mday
(tm: &READ(tm_struct)):<> int = "atslib_tm_get_mday"
fun tm_get_mon
(tm: &READ(tm_struct)):<> int = "atslib_tm_get_mon"
fun tm_get_year
(tm: &READ(tm_struct)):<> int = "atslib_tm_get_year"
fun tm_get_wday
(tm: &READ(tm_struct)):<> int = "atslib_tm_get_wday"
fun tm_get_yday
(tm: &READ(tm_struct)):<> int = "atslib_tm_get_yday"
fun tm_get_isdst
(tm: &READ(tm_struct)):<> int = "atslib_tm_get_isdst"
(* ****** ****** *)
//
symintr time
//
// HX: error-checking is not forced
//
fun time_get (): time_t = "atslib_time_get"
overload time with time_get
//
fun time_get_and_set // HX: error must be checked!
(p: &time_t? >> opt (time_t, b)): #[b:bool] bool (b)
= "atslib_time_get_and_set" // function!
overload time with time_get_and_set
//
(* ****** ****** *)
//
// HX: [ctime] is non-reentrant
// HX: the returned string ends with a newline.
//
fun ctime
(
t: &READ(time_t)
) :<!ref> [l:addr]
(
strptr l -<lin,prf> void | strptr l
) = "mac#atslib_ctime" // endfun
//
(* ****** ****** *)
//
#define CTIME_BUFSZ 26
//
dataview
ctime_v (m:int, addr, addr) =
| {l:addr}
ctime_v_fail (m, l, null) of b0ytes (m) @ l
| {l:addr | l > null}
ctime_v_succ (m, l, l) of strbuf (m, CTIME_BUFSZ-1) @ l
// end of [ctime_v]
fun ctime_r
{m:int | m >= CTIME_BUFSZ}{l:addr}
(
pf: !b0ytes (m) @ l >> ctime_v (m, l, l1) | t: &READ(time_t), p: ptr l
) :<> #[l1:addr] ptr l1 = "mac#atslib_ctime_r"
// end of [ctime_r]
(* ****** ****** *)
//
// HX:
// [localtime] is non-reentrant
//
fun localtime
(
time: &READ(time_t)
) :<!ref>
[l:addr]
(
vptroutopt (tm_struct, l) | ptr l
) = "mac#atslib_localtime" // endfun
//
(* ****** ****** *)
//
// HX: [localtime_r] is reentrant
//
fun localtime_r
(
time: &READ(time_t)
, tm: &tm_struct? >> opt (tm_struct, l > null)
) :<> #[l:addr] ptr (l) = "mac#atslib_localtime_r"
// end of [localtime_r]
(* ****** ****** *)
//
// HX: [gmtime] is non-reentrant
//
fun gmtime (
time: &READ(time_t)
) :<!ref>
[l:addr] (
vptroutopt (tm_struct, l)
| ptr l
) = "mac#atslib_gmtime"
// end of [gmtime]
//
// HX: [gmtime_r] is reentrant
//
fun gmtime_r (
time: &READ(time_t), tm: &tm_struct? >> opt (tm_struct, l > null)
) :<> #[l:addr] ptr l = "mac#atslib_gmtime_r"
// end of [gmtime_r]
(* ****** ****** *)
fun mktime (
tm: &READ(tm_struct)
) : time_t
= "mac#atslib_mktime" // returns -1 on error
// end of [mktime]
(* ****** ****** *)
fun asctime (
tm: &READ(tm_struct)
) :<!ref>
[l:addr] (
strptr l -<lin,prf> void
| strptr l
) = "mac#atslib_asctime"
// end of [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: &READ(tm_struct)
) :<> #[n:nat | n < m] size_t n
= "mac#atslib_strftime" // this a macro!
// end of [strftime]
(* ****** ****** *)
(*
//
// HX-2010-09-26:
// the function is not in FreeBSD or Darwin;
// [getdate] sets [getdate_err] if an error occurs
//
fun getdate_err_get ():<> int = "atslib_getdate_err_get"
fun getdate_err_set (x: int):<> void = "atslib_getdate_err_set"
fun getdate (str: string):<!ref>
[l:addr] (ptroutopt (tm_struct, l) | ptr l) = "mac#atslib_getdate"
// end of [getdate]
*)
//
// -D_XOPEN_SOURCE
//
fun strptime (
str: string, fmt: string
, tm: &tm_struct? >> opt (tm_struct, l > null)
) : #[l:addr] ptr l
= "mac#atslib_strptime" // HX: it returns NULL on error
// end of [strptime]
(* ****** ****** *)
(*
extern int daylight ; // not in FreeBSD or Darwin
extern long int timezone ; // not in FreeBSD or Darwin
extern char *tzname[2] ; // not in FreeBSD or Darwin
*)
fun tzset ():<!ref> void = "mac#atslib_tzset"
(* ****** ****** *)
typedef clock_t = $TYPES.clock_t
macdef CLOCKS_PER_SEC = $extval (clock_t, "CLOCKS_PER_SEC")
//
// HX: these are implemented in libc/sys/CATS/types.cats
//
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 = "mac#atslib_clock" // HX: it returns -1 on error
(* ****** ****** *)
typedef
timespec_struct =
$extype_struct
"ats_timespec_type" of {
tv_sec= time_t // seconds
, tv_nsec= lint // nanoseconds
} // end of [timespec_struct]
typedef timespec = timespec_struct
(* ****** ****** *)
//
// HX: 0/-1 : succ/fail // errno set to EINTR
//
fun nanosleep (
nsec: &READ(timespec)
, rem: ×pec? >> opt (timespec, i==0)
) : #[i:int | i <= 0] int(i) = "mac#atslib_nanosleep"
// end of [nanosleep]
fun nanosleep_null
(nsec: &READ(timespec)): int = "mac#atslib_nanosleep_null"
// end of [nanosleep_null]
(* ****** ****** *)
typedef clockid_t = $TYPES.clockid_t
macdef CLOCK_REALTIME = $extval (clockid_t, "CLOCK_REALTIME")
macdef CLOCK_MONOTONIC = $extval (clockid_t, "CLOCK_MONOTONIC")
(*
macdef CLOCK_THREAD_CPUTIME_ID = $extval (clockid_t, "CLOCK_THREAD_CPUTIME_ID")
macdef CLOCK_PROCESS_CPUTIME_ID = $extval (clockid_t, "CLOCK_PROCESS_CPUTIME_ID")
*)
(* ****** ****** *)
//
// HX: 0/-1 : succ/fail // errno set
//
fun clock_gettime
(
id: clockid_t
, tp: ×pec? >> opt (timespec, i==0)
) : #[i:int | i <= 0] int(i) = "mac#atslib_clock_gettime"
// end of [clock_gettime]
//
// HX: 0/-1 : succ/fail // errno set
//
fun clock_getres
(
id: clockid_t
, tp: ×pec? >> opt (timespec, i==0)
) : #[i:int | i <= 0] int(i) = "mac#atslib_clock_getres"
// end of [clock_getres]
//
// HX: 0/-1 : succ/fail // errno set
// HX: superuser privilege is needed for this one
//
fun clock_settime
(id: clockid_t, tp: &READ(timespec)): int = "mac#atslib_clock_settime"
// end of [clock_settime]
(* ****** ****** *)
absview timer_v (i:int)
typedef timer_t (i:int) = $TYPES.timer_t (i)
(* ****** ****** *)
typedef
itimerspec_struct =
$extype_struct "ats_itimerspec_type" of
{
it_interval= timespec (*reset*), it_value= timespec (*current*)
} // end of [itimerspec_struct]
typedef itimerspec = itimerspec_struct
(* ****** ****** *)
//
// HX: 0/-1 : succ/fail // errno set
//
fun timer_create_null (
cid: clockid_t
, tid: &timer_t? >> opt (timer_t(id), i==0)
) : #[i,id:int | i <= 0] (
option_v (timer_v(id), i==0)
| int (i)
) = "mac#atslib_timer_create_null"
// end of [timer_create_null]
//
// HX: 0/-1 : succ/fail // errno set
//
fun timer_delete {id:int} (
pf: !timer_v(id) >> option_v (timer_v(id), i < 0)
| tid: timer_t (id)
) : #[i:int | i <= 0] int (i)
= "mac#atslib_timer_delete"
// end of [timer_delete]
(* ****** ****** *)
//
// HX: 0/-1 : succ/fail // errno set
//
fun timer_gettime {id:int} (
pf: !timer_v (id)
| tid: timer_t (id)
, itp: &itimerspec? >> opt (itimerspec, i==0)
) : #[i: int | i <= 0] int (i)
= "mac#atslib_timer_gettime"
// end of [timer_gettime]
fun timer_settime {id:int} (
pf: !timer_v (id)
| tid: timer_t (id)
, newitp: &READ(itimerspec)
, olditp: &itimerspec? >> opt (itimerspec, i==0)
) : #[i: int | i <= 0] int (i)
= "mac#atslib_timer_settime"
// end of [timer_settime]
(* ****** ****** *)
//
// HX: 0/-1 : succ/fail // errno set
//
fun timer_getoverrun
{id:int} (
pf: !timer_v (id) | tid: timer_t (id)
) : intGte (~1)
= "mac#atslib_timer_getoverrun"
// end of [timer_getoverrun]
(* ****** ****** *)
(* end of [time.sats] *)
|