Retrieve gettimeofday() from sys/time.h

Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
AnErrupTion 2024-08-01 14:23:52 +02:00
parent 61f3fadfbf
commit d40ec873a7
No known key found for this signature in database
GPG Key ID: 3E85EB44F610AD7F
4 changed files with 16 additions and 12 deletions

View File

@ -477,8 +477,8 @@ fn addUtmpEntry(entry: *Utmp, username: [*:0]const u8, pid: c_int) !void {
host[0] = 0;
entry.ut_host = host;
var tv: std.c.timeval = undefined;
_ = std.c.gettimeofday(&tv, null);
var tv: interop.system_time.timeval = undefined;
_ = interop.system_time.gettimeofday(&tv, null);
entry.ut_tv = .{
.tv_sec = @intCast(tv.tv_sec),

View File

@ -102,8 +102,8 @@ const E = [_]u21{
pub fn clockCell(animate: bool, char: u8, fg: u16, bg: u16) [SIZE]termbox.tb_cell {
var cells: [SIZE]termbox.tb_cell = undefined;
var tv: std.c.timeval = undefined;
_ = std.c.gettimeofday(&tv, null);
var tv: interop.system_time.timeval = undefined;
_ = interop.system_time.gettimeofday(&tv, null);
const clock_chars = toBigNumber(if (animate and char == ':' and @divTrunc(tv.tv_usec, 500000) != 0) ' ' else char);
for (0..cells.len) |i| cells[i] = utils.initCell(clock_chars[i], fg, bg);

View File

@ -25,6 +25,10 @@ pub const time = @cImport({
@cInclude("time.h");
});
pub const system_time = @cImport({
@cInclude("sys/time.h");
});
pub const stdlib = @cImport({
@cInclude("stdlib.h");
});

View File

@ -67,8 +67,8 @@ pub fn main() !void {
// to be able to stop the animation after some time
var tv_zero: std.c.timeval = undefined;
_ = std.c.gettimeofday(&tv_zero, null);
var tv_zero: interop.system_time.timeval = undefined;
_ = interop.system_time.gettimeofday(&tv_zero, null);
var animation_timed_out: bool = false;
const allocator = gpa.allocator();
@ -545,8 +545,8 @@ pub fn main() !void {
timeout = config.min_refresh_delta;
// check how long we have been running so we can turn off the animation
var tv: std.c.timeval = undefined;
_ = std.c.gettimeofday(&tv, null);
var tv: interop.system_time.timeval = undefined;
_ = interop.system_time.gettimeofday(&tv, null);
if (config.animation_timeout_sec > 0 and tv.tv_sec - tv_zero.tv_sec > config.animation_timeout_sec) {
animation_timed_out = true;
@ -557,13 +557,13 @@ pub fn main() !void {
}
}
} else if (config.bigclock and config.clock == null) {
var tv: std.c.timeval = undefined;
_ = std.c.gettimeofday(&tv, null);
var tv: interop.system_time.timeval = undefined;
_ = interop.system_time.gettimeofday(&tv, null);
timeout = @intCast((60 - @rem(tv.tv_sec, 60)) * 1000 - @divTrunc(tv.tv_usec, 1000) + 1);
} else if (config.clock != null or auth_fails >= 10) {
var tv: std.c.timeval = undefined;
_ = std.c.gettimeofday(&tv, null);
var tv: interop.system_time.timeval = undefined;
_ = interop.system_time.gettimeofday(&tv, null);
timeout = @intCast(1000 - @divTrunc(tv.tv_usec, 1000) + 1);
}