libresman
diff 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 diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/filewatch_bsd.c Mon Mar 31 19:51:00 2014 +0300 1.3 @@ -0,0 +1,25 @@ 1.4 +/* file modification monitoring with kqueue */ 1.5 +#if defined(__FreeBSD__) || defined(__APPLE__) 1.6 +#include <stdio.h> 1.7 +#include <fcntl.h> 1.8 +#include <sys/event.h> 1.9 +#include "filewatch.h" 1.10 +#include "resman.h" 1.11 +#include "resman_impl.h" 1.12 + 1.13 +int resman_init_file_monitor(struct resman *rman) 1.14 +{ 1.15 + if((rman->kq = kqueue()) == -1) { 1.16 + return -1; 1.17 + } 1.18 + /* set non-blocking flag, to allow polling by reading */ 1.19 + fcntl(rman->kq, F_SETFL, fcntl(rman->kq, F_GETFL) | O_NONBLOCK); 1.20 + 1.21 + /* createh the fd->resource map */ 1.22 + rman->nresmap = rb_create(RB_KEY_INT); 1.23 + return 0; 1.24 +} 1.25 + 1.26 +#else 1.27 +int resman_filewatch_bsd_silence_empty_file_warning; 1.28 +#endif /* __FreeBSD__ or __APPLE__ */