Guest User

Untitled

a guest
May 27th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #include <sys/inotify.h>
  2. #include <stdio.h>
  3. #include <errno.h>
  4.  
  5. /* size of the event structure, not counting name */
  6. #define EVENT_SIZE (sizeof (struct inotify_event))
  7.  
  8. /* reasonable guess as to size of 1024 events */
  9. #define BUF_LEN (1024 * (EVENT_SIZE + 16))
  10.  
  11. int fd;
  12. int wd;
  13. char buf[BUF_LEN];
  14. int len, i = 0;
  15.  
  16.  
  17. int main()
  18. {
  19.  
  20. fd = inotify_init();
  21.  
  22. wd = inotify_add_watch(fd, "foo.txt", IN_MODIFY);
  23.  
  24. len = read (fd, buf, BUF_LEN);
  25.  
  26. while (i < len) {
  27. struct inotify_event *event;
  28.  
  29. event = (struct inotify_event *) &buf[i];
  30.  
  31. if (event->mask & IN_IGNORED)
  32. puts("IN_IGNORED");
  33.  
  34. if (event->mask & IN_MODIFY)
  35. puts("IN_MODIFY");
  36.  
  37. i += EVENT_SIZE + event->len;
  38. }
  39. return 0;
  40. }
Add Comment
Please, Sign In to add comment