summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2009-07-19 18:56:19 +0000
committerDimitri Sokolyuk <demon@dim13.org>2009-07-19 18:56:19 +0000
commit0d9838b7712b9f2a8732f2989f9af05926533319 (patch)
tree35fab62bb461391a3704c963b87f82ee5b3969be
parent285e17dab30678e5b868d1250b3b2c29bcd7854e (diff)
use more precise timings
-rw-r--r--aclock.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/aclock.c b/aclock.c
index 9188b0c..c91a71c 100644
--- a/aclock.c
+++ b/aclock.c
@@ -36,12 +36,12 @@ catch(int sig)
}
void
-settimer(int sec)
+settimer(int sec, int usec)
{
struct itimerval itv;
itv.it_value.tv_sec = sec;
- itv.it_value.tv_usec = 0;
+ itv.it_value.tv_usec = usec;
itv.it_interval = itv.it_value;
setitimer(ITIMER_REAL, &itv, NULL);
@@ -86,16 +86,19 @@ main(void)
time_t t;
struct tm *ltime;
struct winsize ws;
+ struct timeval tv;
signal(SIGWINCH, catch);
signal(SIGALRM, catch);
signal(SIGINT, catch);
- settimer(1);
initscr();
curs_set(0);
while (!die) {
+ gettimeofday(&tv, NULL);
+ settimer(0, 1000000 - tv.tv_usec);
+
if (redraw && ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) != -1) {
resizeterm(ws.ws_row, ws.ws_col);
clear();