From: tb Date: Mon, 11 Dec 2017 23:33:44 +0000 (+0000) Subject: The code can be simplified by using clock_gettime(2)'s CLOCK_REALTIME X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=77b728da666f4e207131015d6e6ea34c9c630981;p=openbsd The code can be simplified by using clock_gettime(2)'s CLOCK_REALTIME instead of gettimeofday(2). From Scott Cheloha, ok jca --- diff --git a/games/grdc/grdc.c b/games/grdc/grdc.c index 9c9ef0518f9..d6a02e74641 100644 --- a/games/grdc/grdc.c +++ b/games/grdc/grdc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: grdc.c,v 1.27 2017/07/13 02:57:52 tb Exp $ */ +/* $OpenBSD: grdc.c,v 1.28 2017/12/11 23:33:44 tb Exp $ */ /* * * Copyright 2002 Amos Shapir. Public domain. @@ -18,6 +18,7 @@ #include #include #include +#include #include #define XLENGTH 58 @@ -61,8 +62,7 @@ main(int argc, char *argv[]) int i, j, s, k; int scrol; int n = 0; - struct timeval nowtv, endtv; - struct timespec delay; + struct timespec delay, end; const char *errstr; long scroldelay = 50000000; int xbase; @@ -119,10 +119,9 @@ main(int argc, char *argv[]) curs_set(0); sigwinched = 1; /* force initial sizing */ - gettimeofday(&nowtv, NULL); - TIMEVAL_TO_TIMESPEC(&nowtv, &now); + clock_gettime(CLOCK_REALTIME, &now); if (n) - endtv.tv_sec = nowtv.tv_sec + n - 1; + end.tv_sec = now.tv_sec + n - 1; do { if (sigwinched) { sigwinched = 0; @@ -205,8 +204,7 @@ main(int argc, char *argv[]) } } if (scrol && k <= 4) { - gettimeofday(&nowtv, NULL); - TIMEVAL_TO_TIMESPEC(&nowtv, &now); + clock_gettime(CLOCK_REALTIME, &now); delay.tv_sec = 0; delay.tv_nsec = 1000000000 - now.tv_nsec - (4-k) * scroldelay; @@ -217,8 +215,7 @@ main(int argc, char *argv[]) } move(6, 0); refresh(); - gettimeofday(&nowtv, NULL); - TIMEVAL_TO_TIMESPEC(&nowtv, &now); + clock_gettime(CLOCK_REALTIME, &now); delay.tv_sec = 0; delay.tv_nsec = (1000000000 - now.tv_nsec); /* want scrolling to END on the second */ @@ -234,7 +231,7 @@ main(int argc, char *argv[]) endwin(); errx(1, "terminated by signal %d", sigtermed); } - } while (n == 0 || nowtv.tv_sec < endtv.tv_sec); + } while (n == 0 || now.tv_sec < end.tv_sec); standend(); clear(); refresh();