# HG changeset patch # User John Tsiombikas # Date 1396284660 -10800 # Node ID 6b9974a8bdae97c9965e466a308171a1e8a1ca2c # Parent 1be0a35aa2164b31a266397dca40caff98c3edca started BSD/mac support for file watching diff -r 1be0a35aa216 -r 6b9974a8bdae examples/imgthumbs/Makefile --- a/examples/imgthumbs/Makefile Thu Feb 13 21:34:41 2014 +0200 +++ b/examples/imgthumbs/Makefile Mon Mar 31 19:51:00 2014 +0300 @@ -5,7 +5,7 @@ obj = $(src:.c=.o) bin = imgthumbs -CFLAGS = -pedantic -Wall -g -I../../src +CFLAGS = -pedantic -Wall -g -I../../src -Wno-deprecated-declarations LDFLAGS = $(libgl) -limago $(resman) -lpthread ifeq ($(shell uname -s), Darwin) diff -r 1be0a35aa216 -r 6b9974a8bdae src/filewatch_bsd.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/filewatch_bsd.c Mon Mar 31 19:51:00 2014 +0300 @@ -0,0 +1,25 @@ +/* file modification monitoring with kqueue */ +#if defined(__FreeBSD__) || defined(__APPLE__) +#include +#include +#include +#include "filewatch.h" +#include "resman.h" +#include "resman_impl.h" + +int resman_init_file_monitor(struct resman *rman) +{ + if((rman->kq = kqueue()) == -1) { + return -1; + } + /* set non-blocking flag, to allow polling by reading */ + fcntl(rman->kq, F_SETFL, fcntl(rman->kq, F_GETFL) | O_NONBLOCK); + + /* createh the fd->resource map */ + rman->nresmap = rb_create(RB_KEY_INT); + return 0; +} + +#else +int resman_filewatch_bsd_silence_empty_file_warning; +#endif /* __FreeBSD__ or __APPLE__ */ diff -r 1be0a35aa216 -r 6b9974a8bdae src/resman_impl.h --- a/src/resman_impl.h Thu Feb 13 21:34:41 2014 +0200 +++ b/src/resman_impl.h Mon Mar 31 19:51:00 2014 +0300 @@ -10,6 +10,9 @@ #include #include #endif +#if defined(__FreeBSD__) || defined(__APPLE__) +#include +#endif #ifdef WIN32 #include #endif @@ -33,6 +36,9 @@ #ifdef __linux__ int nfd; #endif +#if defined(__FreeBSD__) || defined(__APPLE__) + struct kevent kev; +#endif }; @@ -56,6 +62,9 @@ int inotify_fd; struct rbtree *modset; #endif +#if defined(__FreeBSD__) || defined(__APPLE__) + int kq; +#endif #ifdef WIN32 struct rbtree *watchdirs, *wdirbyev; HANDLE *watch_handles; /* dynamic array of all the watched directory handles */