From 2497c1392b81e093f4de2541a98746aebd449a7f Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Wed, 26 Sep 2012 15:04:18 +0200 Subject: Initial commit --- inotify.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 inotify.c (limited to 'inotify.c') diff --git a/inotify.c b/inotify.c new file mode 100644 index 0000000..d363c77 --- /dev/null +++ b/inotify.c @@ -0,0 +1,92 @@ +#include +#include +#include +#include + +#include +#include +#define fail(msg) error(1, errno, msg) + +#ifndef PATH_MAX +# define PATH_MAX 4096 +#endif + +struct ev { + int val; + char *name; +}; + +#define STRVAL(val) #val +#define IN(name) {IN_##name, STRVAL(name)} + +struct ev events[] = { + IN(CLOSE_WRITE), + IN(CLOSE_NOWRITE), + IN(OPEN), + {0, NULL} +}; + +int main(int argc, char **argv) { + int i, ifd, wfd, mask; + int wfds[argc - 1]; + if (argc < 2) { + fprintf(stderr, "Usage: %s file_to_watch ...\n", argv[0]); + return 1; + } + for (i=1; iname != NULL) { + mask |= event->val; + printf("event IN_%-16s = %8x\n", event->name, event->val); + ++event; + } + for (i=1; iwd) { + file = argv[i + 1]; + break; + } + } + printf("wd = %i, mask = %x, name = %s\tfile = %s\n", + iev->wd, iev->mask, iev->name, + file); + } + + free(iev); + + for (i=0; i