hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 41f12dfccfe58105b9ecfa8383ed08c21448fa62
parent 1380705105a2926f265866f70809fd7864464c73
Author: Drew DeVault <sir@cmpwn.com>
Date:   Wed, 13 Apr 2022 15:23:43 +0200

time::chrono: initialize leap seconds

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Mos/+linux/fs.ha | 11+++++++++--
Mtime/chrono/leapsec.ha | 17+++++++++--------
Mtime/chrono/timescale.ha | 4----
3 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/os/+linux/fs.ha b/os/+linux/fs.ha @@ -7,9 +7,16 @@ use path; use rt; use strings; -@init fn init() void = { +export fn init_cwd() void = { + // XXX: Workaround for https://todo.sr.ht/~sircmpwn/hare/616 static let cwd_fs = os_filesystem { ... }; - cwd = static_dirfdopen(rt::AT_FDCWD, &cwd_fs); + if (cwd_fs.dirfd == 0) { + cwd = static_dirfdopen(rt::AT_FDCWD, &cwd_fs); + }; +}; + +@init fn init() void = { + init_cwd(); }; // Returns the current working directory. The return value is statically diff --git a/time/chrono/leapsec.ha b/time/chrono/leapsec.ha @@ -1,5 +1,6 @@ use bufio; use fmt; +use fs; use io; use os; use strconv; @@ -32,14 +33,14 @@ export def UTC_LEAPSECS_FILE: str = "/usr/share/zoneinfo/leap-seconds.list"; // UTC timestamps and their TAI offsets, sourced from leap-seconds.list let utc_leapsecs: [](i64, i64) = []; -// TODO: Fix, cannot compile harec2 with this line. This code is currenlty -// called where it's needed, as a workaround. Remember to prune this function -// call elsewhere once this @init is fixed. -// -//@init fn init_utc_leapsecs() void = init_utc_leapsecs(); - -fn init_utc_leapsecs() void = { - const file = os::open(UTC_LEAPSECS_FILE)!; +@init fn init_utc_leapsecs() void = { + os::init_cwd(); + const file = match (os::open(UTC_LEAPSECS_FILE)) { + case let file: io::file => + yield file; + case fs::error => + return; + }; read_leapsecfile(file, &utc_leapsecs)!; }; diff --git a/time/chrono/timescale.ha b/time/chrono/timescale.ha @@ -46,8 +46,6 @@ export const utc: timescale = timescale { }; fn conv_tai_utc(a: time::instant) (time::instant | time::error) = { - init_utc_leapsecs(); - const idx = lookup_leaps(utc_leapsecs, time::unix(a)); const ofst = utc_leapsecs[idx].1; @@ -63,8 +61,6 @@ fn conv_tai_utc(a: time::instant) (time::instant | time::error) = { }; fn conv_utc_tai(a: time::instant) (time::instant | time::error) = { - init_utc_leapsecs(); - const idx = lookup_leaps(utc_leapsecs, time::unix(a)); const ofst = utc_leapsecs[idx].1;