summaryrefslogtreecommitdiffstats
path: root/games
diff options
context:
space:
mode:
authoruqs <uqs@FreeBSD.org>2010-08-03 20:56:23 +0000
committeruqs <uqs@FreeBSD.org>2010-08-03 20:56:23 +0000
commit25440e11e9a883c573d37a45aa87b288eb8d7368 (patch)
tree8e708990e51a5cb7cbdc029e8d3e701f11552df7 /games
parentbacd73115af468793b033705cb042e0d6519c1a4 (diff)
downloadFreeBSD-src-25440e11e9a883c573d37a45aa87b288eb8d7368.zip
FreeBSD-src-25440e11e9a883c573d37a45aa87b288eb8d7368.tar.gz
grdc(6): de-obfuscate the timekeeping of now/delay
- 'now' only contains current time readings - delay is only used as parameter to nanosleep - prev_sec contains the time_t of the previous loop iteration Submitted by: bde MFC after: 2 weeks
Diffstat (limited to 'games')
-rw-r--r--games/grdc/grdc.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/games/grdc/grdc.c b/games/grdc/grdc.c
index fa920da..6881cf1 100644
--- a/games/grdc/grdc.c
+++ b/games/grdc/grdc.c
@@ -55,6 +55,7 @@ int
main(int argc, char *argv[])
{
struct timespec delay;
+ time_t prev_sec;
long t, a;
int i, j, s, k;
int n;
@@ -138,6 +139,7 @@ main(int argc, char *argv[])
attrset(COLOR_PAIR(2));
}
clock_gettime(CLOCK_REALTIME_FAST, &now);
+ prev_sec = now.tv_sec;
do {
mask = 0;
tm = localtime(&now.tv_sec);
@@ -194,20 +196,20 @@ main(int argc, char *argv[])
}
movto(6, 0);
refresh();
- clock_gettime(CLOCK_REALTIME_FAST, &delay);
- if (delay.tv_sec == now.tv_sec) {
+ clock_gettime(CLOCK_REALTIME_FAST, &now);
+ if (now.tv_sec == prev_sec) {
if (delay.tv_nsec > 0) {
delay.tv_sec = 0;
- delay.tv_nsec = 1000000000 - delay.tv_nsec;
+ delay.tv_nsec = 1000000000 - now.tv_nsec;
} else {
delay.tv_sec = 1;
delay.tv_nsec = 0;
}
nanosleep(&delay, NULL);
- clock_gettime(CLOCK_REALTIME_FAST, &delay);
+ clock_gettime(CLOCK_REALTIME_FAST, &now);
}
- n -= delay.tv_sec - now.tv_sec;
- now.tv_sec = delay.tv_sec;
+ n -= now.tv_sec - prev_sec;
+ prev_sec = now.tv_sec;
if (sigtermed) {
standend();
clear();
OpenPOWER on IntegriCloud