Update watch(1) to handle more accurate intervals - ubase - suckless linux base utils
 (HTM) git clone git://git.suckless.org/ubase
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 703e18185c38b869d8f001241aa6b33c832ff5dc
 (DIR) parent 4cb108f557d6c34f22166430f853e64335e94461
 (HTM) Author: sin <sin@2f30.org>
       Date:   Sun, 30 Nov 2014 14:03:25 +0000
       
       Update watch(1) to handle more accurate intervals
       
       Diffstat:
         M watch.c                             |      14 ++++++++++----
       
       1 file changed, 10 insertions(+), 4 deletions(-)
       ---
 (DIR) 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;
        }