Skip to content

Commit

Permalink
Initial useful code
Browse files Browse the repository at this point in the history
  • Loading branch information
ggreer committed Apr 12, 2012
1 parent ffff589 commit 1e7473f
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions notifywait.c
@@ -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.