-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
79 lines (58 loc) · 2.72 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* Compile with con gcc -framework CoreServices main.c -o main_c */
#include <stdlib.h>
#include <CoreServices/CoreServices.h>
int eventModified = kFSEventStreamEventFlagItemFinderInfoMod |
kFSEventStreamEventFlagItemModified |
kFSEventStreamEventFlagItemInodeMetaMod |
kFSEventStreamEventFlagItemChangeOwner |
kFSEventStreamEventFlagItemXattrMod;
int eventRenamed = kFSEventStreamEventFlagItemCreated |
kFSEventStreamEventFlagItemRemoved |
kFSEventStreamEventFlagItemRenamed;
int eventSystem = kFSEventStreamEventFlagUserDropped |
kFSEventStreamEventFlagKernelDropped |
kFSEventStreamEventFlagEventIdsWrapped |
kFSEventStreamEventFlagHistoryDone |
kFSEventStreamEventFlagMount |
kFSEventStreamEventFlagUnmount |
kFSEventStreamEventFlagRootChanged;
void myCallbackFunction(
ConstFSEventStreamRef streamRef,
void *clientCallBackInfo,
size_t numEvents,
void *eventPaths,
const FSEventStreamEventFlags eventFlags[],
const FSEventStreamEventId eventIds[]
){
int i;
char **paths = eventPaths;
for( i=0; i < numEvents; i++ ){
printf( "Changed %s\n", paths[i] );
printf( " Modified : %d\n", !!( eventFlags[i] & eventModified ) );
printf( " Renamed : %d\n", !!( eventFlags[i] & eventRenamed ) );
printf( " System : %d\n", !!( eventFlags[i] & eventSystem ) );
}
}
int main( int argc, char* argv[] ){
/* Define variables and create a CFArray object containing CFString objects containing paths to watch. */
CFStringRef mypath = CFStringCreateWithCString( NULL, argv[ 1 ], kCFStringEncodingUTF8);
CFArrayRef pathsToWatch = CFArrayCreate( NULL, ( const void ** ) &mypath, 1, NULL );
void *callbackInfo = NULL; // could put stream-specific data here. FSEventStreamRef stream;*/
CFAbsoluteTime latency = 3.0; /* Latency in seconds */
FSEventStreamRef stream;
/* Create the stream, passing in a callback */
stream = FSEventStreamCreate(
NULL,
&myCallbackFunction,
callbackInfo,
pathsToWatch,
kFSEventStreamEventIdSinceNow, /* Or a previous event ID */
latency,
kFSEventStreamCreateFlagFileEvents /* Flags explained in reference: https://developer.apple.com/library/mac/documentation/Darwin/Reference/FSEvents_Ref/Reference/reference.html */
);
/* Create the stream before calling this. */
FSEventStreamScheduleWithRunLoop( stream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode );
FSEventStreamStart( stream );
CFRunLoopRun();
return 0;
}