libresman

view src/filewatch_bsd.c @ 26:6b9974a8bdae

started BSD/mac support for file watching
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 31 Mar 2014 19:51:00 +0300
parents
children
line source
1 /* file modification monitoring with kqueue */
2 #if defined(__FreeBSD__) || defined(__APPLE__)
3 #include <stdio.h>
4 #include <fcntl.h>
5 #include <sys/event.h>
6 #include "filewatch.h"
7 #include "resman.h"
8 #include "resman_impl.h"
10 int resman_init_file_monitor(struct resman *rman)
11 {
12 if((rman->kq = kqueue()) == -1) {
13 return -1;
14 }
15 /* set non-blocking flag, to allow polling by reading */
16 fcntl(rman->kq, F_SETFL, fcntl(rman->kq, F_GETFL) | O_NONBLOCK);
18 /* createh the fd->resource map */
19 rman->nresmap = rb_create(RB_KEY_INT);
20 return 0;
21 }
23 #else
24 int resman_filewatch_bsd_silence_empty_file_warning;
25 #endif /* __FreeBSD__ or __APPLE__ */