Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#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)
if (event->mask & 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