summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--inotify-watch.c50
1 files changed, 26 insertions, 24 deletions
diff --git a/inotify-watch.c b/inotify-watch.c
index 1a32786..9196c1f 100644
--- a/inotify-watch.c
+++ b/inotify-watch.c
@@ -1,5 +1,5 @@
/*
- * inotify-watchdir.c
+ * inotify-watch.c
*
* Watch a file or directory for changes using inotify
*
@@ -16,39 +16,41 @@
#include <sys/inotify.h>
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*x))
+
struct mask2string {
uint32_t mask;
const char *desc;
};
+#define DECLARE_M2STR(x) { x, #x }
+
static const struct mask2string events[] = {
- { IN_ACCESS, "ACCESS" },
- { IN_MODIFY, "MODIFY" },
- { IN_ATTRIB, "ATTRIB" },
- { IN_CLOSE_WRITE, "CLOSE_WRITE" },
- { IN_CLOSE_NOWRITE, "CLOSE_NOWRITE" },
- { IN_OPEN, "OPEN" },
- { IN_MOVED_FROM, "MOVED_FROM" },
- { IN_MOVED_TO, "MOVED_TO" },
- { IN_CREATE, "CREATE" },
- { IN_DELETE, "DELETE" },
- { IN_DELETE_SELF, "DELETE_SELF" },
- { IN_MOVE_SELF, "MOVE_SELF" },
- { IN_UNMOUNT, "UNMOUNT" },
- { IN_Q_OVERFLOW, "Q_OVERFLOW" },
- { IN_IGNORED, "IGNORED" },
+ DECLARE_M2STR(IN_ACCESS),
+ DECLARE_M2STR(IN_MODIFY),
+ DECLARE_M2STR(IN_ATTRIB),
+ DECLARE_M2STR(IN_CLOSE_WRITE),
+ DECLARE_M2STR(IN_CLOSE_NOWRITE),
+ DECLARE_M2STR(IN_OPEN),
+ DECLARE_M2STR(IN_MOVED_FROM),
+ DECLARE_M2STR(IN_MOVED_TO),
+ DECLARE_M2STR(IN_CREATE),
+ DECLARE_M2STR(IN_DELETE),
+ DECLARE_M2STR(IN_DELETE_SELF),
+ DECLARE_M2STR(IN_MOVE_SELF),
+ DECLARE_M2STR(IN_UNMOUNT),
+ DECLARE_M2STR(IN_Q_OVERFLOW),
+ DECLARE_M2STR(IN_IGNORED),
/* special flags */
- { IN_ONLYDIR, "ONLYDIR" },
- { IN_DONT_FOLLOW, "DONT_FOLLOW" },
- { IN_MASK_ADD, "MASK_ADD" },
- { IN_ONESHOT, "ONESHOT" },
- /* end of array */
- { -1, NULL }
+ DECLARE_M2STR(IN_ONLYDIR),
+ DECLARE_M2STR(IN_DONT_FOLLOW),
+ DECLARE_M2STR(IN_MASK_ADD),
+ DECLARE_M2STR(IN_ONESHOT),
};
static void inotify_print_event(struct inotify_event *inev)
{
- int i;
+ unsigned int i;
/* stat? */
printf("(%s) wd=%04x, cookie=%04x, len=%04x, name=\"%s\" :",
@@ -56,7 +58,7 @@ static void inotify_print_event(struct inotify_event *inev)
inev->wd, inev->cookie, inev->len,
inev->len > 0 ? inev->name : "");
- for (i = 0; events[i].desc; i++)
+ for (i = 0; i < ARRAY_SIZE(events); i++)
if (inev->mask & events[i].mask)
printf(" %s", events[i].desc);