From cbab5e56df05da42ddeb4839005b77c7da2688d4 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sun, 18 Jan 2009 22:57:42 +0100 Subject: Use sys/inotify.h, allocate correct number of watches --- inotify-watch.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/inotify-watch.c b/inotify-watch.c index 7ccf9c4..ccedf2f 100644 --- a/inotify-watch.c +++ b/inotify-watch.c @@ -4,7 +4,8 @@ * Watch a file or directory for changes using inotify * * Copyright (c) Tobias Klauser - * All rights reserved + * + * All rights reserved. */ #include @@ -12,10 +13,8 @@ #include #include #include -#include -#include "inotify.h" -#include "inotify-syscalls.h" +#include struct mask2string { uint32_t mask; @@ -53,7 +52,8 @@ static void inotify_print_event(struct inotify_event *inev) /* stat? */ printf("(%s) wd=%04x, cookie=%04x, len=%04x, name=\"%s\" :", - inev->mask & IN_ISDIR ? "dir" : "file", inev->wd, inev->cookie, inev->len, inev->name); + inev->mask & IN_ISDIR ? "dir" : "file", + inev->wd, inev->cookie, inev->len, inev->name); for (i = 0; events[i].desc; i++) if (inev->mask & events[i].mask) @@ -82,7 +82,7 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } - watches = malloc(argc * sizeof(int)); + watches = malloc((argc - 1) * sizeof(int)); if (!watches) { perror("malloc"); exit(EXIT_FAILURE); @@ -105,7 +105,8 @@ int main(int argc, char *argv[]) inotify_print_event(inev); len -= sizeof(struct inotify_event) + inev->len; - inev = (struct inotify_event *) ((char *) inev + sizeof(struct inotify_event) + inev->len); + inev = (struct inotify_event *) ((char *) inev + + sizeof(struct inotify_event) + inev->len); } } -- cgit v1.2.3-54-g00ecf