Guest User

Untitled

a guest
Apr 16th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. #include <CoreServices/CoreServices.h>
  2.  
  3. static void callback(ConstFSEventStreamRef streamRef,
  4. void *clientCallBackInfo,
  5. size_t numEvents,
  6. void *eventPaths,
  7. const FSEventStreamEventFlags eventFlags[],
  8. const FSEventStreamEventId eventIds[]) {
  9. exit(0);
  10. }
  11.  
  12. int main (int argc, const char * argv[]) {
  13. // Show help
  14. if (argc != 2 || strncmp(argv[1], "-h", 2) == 0) {
  15. printf("Sleep until a file in or below the watchdir is modified.\n");
  16. printf("Usage: fsevent_sleep /path/to/watchdir\n");
  17. exit(1);
  18. }
  19.  
  20. // Create event stream
  21. CFStringRef pathToWatch = CFStringCreateWithCString(kCFAllocatorDefault, argv[1], kCFStringEncodingUTF8);
  22. CFArrayRef pathsToWatch = CFArrayCreate(NULL, (const void **)&pathToWatch, 1, NULL);
  23. void *callbackInfo = NULL;
  24. FSEventStreamRef stream;
  25. CFAbsoluteTime latency = 1.0;
  26. stream = FSEventStreamCreate(
  27. kCFAllocatorDefault,
  28. callback,
  29. callbackInfo,
  30. pathsToWatch,
  31. kFSEventStreamEventIdSinceNow,
  32. latency,
  33. kFSEventStreamCreateFlagNone
  34. );
  35.  
  36. // Add stream to run loop
  37. FSEventStreamScheduleWithRunLoop(stream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
  38. FSEventStreamStart(stream);
  39. CFRunLoopRun();
  40.  
  41. // Exit
  42. return 2;
  43. }
Add Comment
Please, Sign In to add comment