ubase

suckless linux base utils
git clone git://git.2f30.org/ubase.git
Log | Files | Refs | README | LICENSE

commit 19634fa7b3075231bca065283cb2f094a4098b73
parent 1a59ea784dccc652e77fde1b244cdc9433529e0c
Author: sin <sin@2f30.org>
Date:   Sun Nov 30 14:03:25 +0000

Update watch(1) to handle more accurate intervals

Diffstat:
watch.c | 14++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/watch.c b/watch.c @@ -1,4 +1,5 @@ /* See LICENSE file for copyright and license details. */ +#include <errno.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -15,14 +16,19 @@ int main(int argc, char *argv[]) { char cmd[BUFSIZ]; - int i, interval = 2; + char *end; + useconds_t interval = 2 * 1E6; + float period; + int i; ARGBEGIN { case 't': break; case 'n': - /* Only whole seconds for now */ - interval = estrtol(EARGF(usage()), 10); + period = strtof(EARGF(usage()), &end); + if (*end != '\0' || errno != 0) + eprintf("invalid interval\n"); + interval = period * 1E6; break; default: usage(); @@ -44,7 +50,7 @@ main(int argc, char *argv[]) printf("\x1b[2J\x1b[H"); /* clear */ fflush(NULL); system(cmd); - sleep(interval); + usleep(interval); } return 0; }