[hackers] [ubase] Update watch(1) to handle more accurate intervals || sin

From: <git_AT_suckless.org>
Date: Sun, 30 Nov 2014 15:05:53 +0100

commit 703e18185c38b869d8f001241aa6b33c832ff5dc
Author: sin <sin_AT_2f30.org>
Date: Sun Nov 30 14:03:25 2014 +0000

    Update watch(1) to handle more accurate intervals

diff --git a/watch.c b/watch.c
index 46411df..1508883 100644
--- a/watch.c
+++ b/watch.c
_AT_@ -1,4 +1,5 @@
 /* See LICENSE file for copyright and license details. */
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
_AT_@ -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();
_AT_@ -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;
 }
Received on Sun Nov 30 2014 - 15:05:53 CET

This archive was generated by hypermail 2.3.0 : Sun Nov 30 2014 - 15:12:09 CET