Introduction
Introduction Statistics Contact Development Disclaimer Help
Update watch(1) to handle more accurate intervals - ubase - suckless linux base…
git clone git://git.suckless.org/ubase
Log
Files
Refs
README
LICENSE
---
commit 703e18185c38b869d8f001241aa6b33c832ff5dc
parent 4cb108f557d6c34f22166430f853e64335e94461
Author: sin <[email protected]>
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(-)
---
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;
}
You are viewing proxied material from suckless.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.