libresman
annotate 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 |
rev | line source |
---|---|
nuclear@26 | 1 /* file modification monitoring with kqueue */ |
nuclear@26 | 2 #if defined(__FreeBSD__) || defined(__APPLE__) |
nuclear@26 | 3 #include <stdio.h> |
nuclear@26 | 4 #include <fcntl.h> |
nuclear@26 | 5 #include <sys/event.h> |
nuclear@26 | 6 #include "filewatch.h" |
nuclear@26 | 7 #include "resman.h" |
nuclear@26 | 8 #include "resman_impl.h" |
nuclear@26 | 9 |
nuclear@26 | 10 int resman_init_file_monitor(struct resman *rman) |
nuclear@26 | 11 { |
nuclear@26 | 12 if((rman->kq = kqueue()) == -1) { |
nuclear@26 | 13 return -1; |
nuclear@26 | 14 } |
nuclear@26 | 15 /* set non-blocking flag, to allow polling by reading */ |
nuclear@26 | 16 fcntl(rman->kq, F_SETFL, fcntl(rman->kq, F_GETFL) | O_NONBLOCK); |
nuclear@26 | 17 |
nuclear@26 | 18 /* createh the fd->resource map */ |
nuclear@26 | 19 rman->nresmap = rb_create(RB_KEY_INT); |
nuclear@26 | 20 return 0; |
nuclear@26 | 21 } |
nuclear@26 | 22 |
nuclear@26 | 23 #else |
nuclear@26 | 24 int resman_filewatch_bsd_silence_empty_file_warning; |
nuclear@26 | 25 #endif /* __FreeBSD__ or __APPLE__ */ |