Created
June 4, 2010 03:12
-
-
Save malclocke/424882 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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