Permalink
Browse files

Merge branch 'master' of github.com:visionmedia/watch

  • Loading branch information...
2 parents 34bcb33 + 6b263c7 commit 81e98c4589785626df792c7a6856452c99e02759 @tj committed Dec 14, 2011
Showing with 34 additions and 8 deletions.
  1. +5 −0 History.md
  2. +3 −3 Makefile
  3. +15 −0 Readme.md
  4. +11 −5 src/watch.c
View
@@ -0,0 +1,5 @@
+
+0.0.3 / 2011-12-11
+==================
+
+ * make POSIX compatible [Dominik Bruhn]
View
@@ -1,6 +1,6 @@
-CFLAGS = -std=c99
-PREFIX = /usr/local
+CFLAGS = -std=c99 -D_POSIX_C_SOURCE=199309L -Wall -pedantic
+PREFIX ?= /usr/local
watch: src/watch.c
$(CC) $< $(CFLAGS) -o $@
@@ -14,4 +14,4 @@ uninstall:
clean:
rm -f watch
-.PHONY: clean install uninstall
+.PHONY: clean install uninstall
View
@@ -23,6 +23,21 @@ Options:
$ make install
```
+Or in your local bin (`~/bin`)
+
+```
+$ PREFIX=~ make install
+```
+
+## About
+
+ This project is very similar to original [watch(1)](http://linux.die.net/man/1/watch) implemented in 1991, differences include:
+
+ - ansi escape sequences (colors etc)
+ - terminal is not cleared
+ - lower default interval of 1s
+ - millisecond interval resolution
+
## Milliseconds resolution
This version of `watch(1)` support millisecond resolution
View
@@ -9,14 +9,15 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <time.h>
#include <fcntl.h>
#include <sys/wait.h>
/*
* Command version.
*/
-#define VERSION "0.0.2"
+#define VERSION "0.0.3"
/*
* Default interval in milliseconds.
@@ -50,7 +51,7 @@ usage() {
"\n"
" -q, --quiet only output stderr\n"
" -i, --interval <n> interval in seconds or ms defaulting to 1\n"
- " -V, --version output version number\n"
+ " -v, --version output version number\n"
" -h, --help output this help information\n"
"\n"
);
@@ -73,7 +74,12 @@ milliseconds(const char *str) {
void
mssleep(int ms) {
- usleep(ms * 1000);
+ struct timespec req = {0};
+ time_t sec = (int)(ms / 1000);
+ ms = ms -(sec * 1000);
+ req.tv_sec = sec;
+ req.tv_nsec = ms * 1000000L;
+ while(-1 == nanosleep(&req, &req)) ;
}
/*
@@ -109,7 +115,7 @@ main(int argc, const char **argv){
int interval = DEFAULT_INTERVAL;
int len = 0;
- char *args[ARGS_MAX] = {};
+ char *args[ARGS_MAX];
for (int i = 1; i < argc; ++i) {
const char *arg = argv[i];
@@ -198,4 +204,4 @@ main(int argc, const char **argv){
}
return 0;
-}
+}

0 comments on commit 81e98c4

Please sign in to comment.