diff options
author | d <d@openbsd.org> | 2000-01-20 12:31:33 +0000 |
---|---|---|
committer | d <d@openbsd.org> | 2000-01-20 12:31:33 +0000 |
commit | a39633580a34db1b0efc667e9ea9def974d5744a (patch) | |
tree | 0c962313c76334154139fde8ba70cb63651e8ef5 /games/grdc | |
parent | set[ug]id, not just setuid (diff) | |
download | wireguard-openbsd-a39633580a34db1b0efc667e9ea9def974d5744a.tar.xz wireguard-openbsd-a39633580a34db1b0efc667e9ea9def974d5744a.zip |
track seconds more accurately. ok pjanzen@
Diffstat (limited to 'games/grdc')
-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(); |