Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |