-/* $OpenBSD: engine.c,v 1.28 2021/06/02 08:32:22 martijn Exp $ */
+/* $OpenBSD: engine.c,v 1.29 2021/07/02 15:34:16 millert Exp $ */
/*
* Copyright (c) 2001, 2007 Can Erkin Acar <canacar@openbsd.org>
*
#include <string.h>
#include <term.h>
#include <unistd.h>
+#include <math.h>
#include <err.h>
/* XXX These are defined in term.h and conflict with our variable names */
TAILQ_ENTRY(view_ent) entries;
};
-useconds_t udelay = 5000000;
+static struct timespec ts_delay = { 5, 0 };
+static struct itimerval it_delay = { { 0, 0 }, { 5, 0 } };
+
int dispstart = 0;
int humanreadable = 0;
int interactive = 1;
read_view();
need_sort = 1;
gotsig_alarm = 0;
- ualarm(udelay, 0);
+ setitimer(ITIMER_REAL, &it_delay, NULL);
}
if (need_sort) {
/* XXX if sort took too long */
if (gotsig_alarm) {
gotsig_alarm = 0;
- ualarm(udelay, 0);
+ setitimer(ITIMER_REAL, &it_delay, NULL);
}
}
if (interactive && need_update == 0)
keyboard();
else if (interactive == 0)
- usleep(udelay);
+ nanosleep(&ts_delay, NULL);
}
if (rawmode == 0)
return(0);
}
+
+void
+refresh_delay(double delay)
+{
+ double secs, frac;
+
+ frac = modf(delay, &secs);
+ ts_delay.tv_sec = secs;
+ ts_delay.tv_nsec = frac * 1000000000.0;
+ if (!timespecisset(&ts_delay))
+ ts_delay.tv_nsec = 1000000000;
+ TIMESPEC_TO_TIMEVAL(&it_delay.it_value, &ts_delay);
+}
-/* $OpenBSD: engine.h,v 1.13 2021/06/02 08:32:22 martijn Exp $ */
+/* $OpenBSD: engine.h,v 1.14 2021/07/02 15:34:16 millert Exp $ */
/*
* Copyright (c) 2001, 2007 Can Erkin Acar <canacar@openbsd.org>
*
void setup_term(int maxpr);
int check_termcap(void);
+void refresh_delay(double delay);
void engine_initialize(void);
void engine_loop(int countmax);
void foreach_view(void (*callback)(field_view *));
extern int sortdir;
-extern useconds_t udelay;
extern int dispstart;
extern int humanreadable;
extern int interactive;
-/* $OpenBSD: main.c,v 1.74 2021/06/02 08:32:22 martijn Exp $ */
+/* $OpenBSD: main.c,v 1.75 2021/07/02 15:34:16 millert Exp $ */
/*
* Copyright (c) 2001, 2007 Can Erkin Acar
* Copyright (c) 2001 Daniel Hartmeier
if (errstr != NULL)
error("s: \"%s\": delay value is %s", buf, errstr);
else {
- udelay = (useconds_t)(del * 1000000);
+ refresh_delay(del);
gotsig_alarm = 1;
naptime = del;
}
errx(1, "\"%s\": delay value is %s", argv[1], errstr);
}
- udelay = (useconds_t)(delay * 1000000.0);
- if (udelay < 1)
- udelay = 1;
-
- naptime = (double)udelay / 1000000.0;
+ refresh_delay(delay);
+ naptime = delay;
gethostname(hostname, sizeof (hostname));
gethz();