diff --git a/notifywait.c b/notifywait.c new file mode 100644 index 0000000..4593c03 --- /dev/null +++ b/notifywait.c @@ -0,0 +1,43 @@ +#include +#include +#include +#include +#include + +#include +#include + +void event_cb(ConstFSEventStreamRef streamRef, void *cb_data, size_t count, void *paths, + const FSEventStreamEventFlags flags[], const FSEventStreamEventId ids[]) { + size_t i; + + for (i = 0; i < count; i++) { + /* flags are unsigned long, IDs are uint64_t */ + printf("Change %llu in %s, flags %lu\n", ids[i], ((char**)paths)[i], (long)flags[i]); + } + + if (count > 0) { + exit(1); + } +} + +int main(int argc, char **argv) { + if (argc < 2) { + printf("No path to watch specified\n"); + exit(1); + } + + CFStringRef cfs_path = CFStringCreateWithCString(NULL, argv[1], kCFStringEncodingUTF8); /* pretty sure I'm leaking this */ + CFArrayRef paths = CFArrayCreate(NULL, (const void **)&cfs_path, 1, NULL); /* ditto */ + void *cb_data = NULL; + FSEventStreamRef stream; + + stream = FSEventStreamCreate(NULL, &event_cb, cb_data, paths, kFSEventStreamEventIdSinceNow, 0, kFSEventStreamCreateFlagNone); + FSEventStreamScheduleWithRunLoop(stream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); + FSEventStreamStart(stream); + + CFRunLoopRun(); + /* We never get here */ + + return(0); +}