Permalink
Browse files

Initial useful code

  • Loading branch information...
1 parent ffff589 commit 1e7473fc112ec3697b50c50179a317943097ce8b @ggreer committed Apr 12, 2012
Showing with 43 additions and 0 deletions.
  1. +43 −0 notifywait.c
View
@@ -0,0 +1,43 @@
+#include <stdarg.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/time.h>
+#include <unistd.h>
+
+#include <CoreFoundation/CoreFoundation.h>
+#include <CoreServices/CoreServices.h>
+
+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);
+}

0 comments on commit 1e7473f

Please sign in to comment.