Skip to content

Instantly share code, notes, and snippets.

@malclocke
Created June 4, 2010 03:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malclocke/424882 to your computer and use it in GitHub Desktop.
Save malclocke/424882 to your computer and use it in GitHub Desktop.
#include <sys/inotify.h>
#include <stdio.h>
#include <errno.h>
/* size of the event structure, not counting name */
#define EVENT_SIZE (sizeof (struct inotify_event))
/* reasonable guess as to size of 1024 events */
#define BUF_LEN (1024 * (EVENT_SIZE + 16))
int fd;
int wd;
char buf[BUF_LEN];
int len, i = 0;
int main()
{
fd = inotify_init();
wd = inotify_add_watch(fd, "foo.txt", IN_MODIFY);
len = read (fd, buf, BUF_LEN);
while (i < len) {
struct inotify_event *event;
event = (struct inotify_event *) &buf[i];
if (event->mask & IN_IGNORED)
puts("IN_IGNORED");
if (event->mask & IN_MODIFY)
puts("IN_MODIFY");
i += EVENT_SIZE + event->len;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment