diff options
author | David Leonard <d@cvs.openbsd.org> | 2000-01-20 12:31:34 +0000 |
---|---|---|
committer | David Leonard <d@cvs.openbsd.org> | 2000-01-20 12:31:34 +0000 |
commit | ea2db320a961d65b84361d9c4e03be702fe36a33 (patch) | |
tree | b87bbea6c44c3ef2b1d771e121c5f9e8de5e0d29 | |
parent | 455923755aa0b6dbac11b1e4285b0cb8c2f8e08d (diff) |
track seconds more accurately. ok pjanzen@
-rw-r--r-- | games/grdc/grdc.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/games/grdc/grdc.c b/games/grdc/grdc.c index 4106db0770e..0b6f2d28c0e 100644 --- a/games/grdc/grdc.c +++ b/games/grdc/grdc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: grdc.c,v 1.5 1998/03/19 11:41:51 pjanzen Exp $ */ +/* $OpenBSD: grdc.c,v 1.6 2000/01/20 12:31:33 d Exp $ */ /* * Grand digital clock for curses compatible terminals * Usage: grdc [-s] [n] -- run for n seconds (default infinity) @@ -15,6 +15,7 @@ #ifndef NONPOSIX #include <unistd.h> #endif +#include <sys/time.h> #define YBASE 10 #define XBASE 10 @@ -22,7 +23,7 @@ #define YDEPTH 7 /* it won't be */ -time_t now; /* yeah! */ +struct timespec now; /* yeah! */ struct tm *tm; short disp[11] = { @@ -55,6 +56,8 @@ main(argc, argv) long t, a; int i, j, s, k; int n = 0; + struct timeval nowtv; + struct timespec delay; /* revoke privs */ setegid(getgid()); @@ -107,10 +110,11 @@ main(argc, argv) attrset(COLOR_PAIR(2)); } + gettimeofday(&nowtv, NULL); + TIMEVAL_TO_TIMESPEC(&nowtv, &now); do { mask = 0; - time(&now); - tm = localtime(&now); + tm = localtime(&now.tv_sec); set(tm->tm_sec%10, 0); set(tm->tm_sec/10, 4); set(tm->tm_min%10, 10); @@ -151,7 +155,13 @@ main(argc, argv) } movto(6, 0); refresh(); - sleep(1); + gettimeofday(&nowtv, NULL); + TIMEVAL_TO_TIMESPEC(&nowtv, &now); + delay.tv_sec = 0; + delay.tv_nsec = (1000000000 - now.tv_nsec); + nanosleep(&delay, NULL); + now.tv_sec++; + if (sigtermed) { standend(); clear(); |