common.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #ifndef fsevent_watch_common_h
  2. #define fsevent_watch_common_h
  3. #include <CoreFoundation/CoreFoundation.h>
  4. #include <CoreServices/CoreServices.h>
  5. #include <unistd.h>
  6. #include <fcntl.h>
  7. #include "compat.h"
  8. #define _str(s) #s
  9. #define _xstr(s) _str(s)
  10. #define COMPILED_AT __DATE__ " " __TIME__
  11. #define FPRINTF_FLAG_CHECK(flags, flag, msg, fd) \
  12. do { \
  13. if ((flags) & (flag)) { \
  14. fprintf(fd, "%s\n", msg); } } \
  15. while (0)
  16. #define FLAG_CHECK_STDERR(flags, flag, msg) \
  17. FPRINTF_FLAG_CHECK(flags, flag, msg, stderr)
  18. /*
  19. * FSEVENTSBITS:
  20. * generated by `make printflags` (and pasted here)
  21. * flags MUST be ordered (bits ascending) and sorted
  22. *
  23. * idea from: http://www.openbsd.org/cgi-bin/cvsweb/src/sbin/ifconfig/ifconfig.c (see printb())
  24. */
  25. #define FSEVENTSBITS \
  26. "\1mustscansubdirs\2userdropped\3kerneldropped\4eventidswrapped\5historydone\6rootchanged\7mount\10unmount\11created\12removed\13inodemetamod\14renamed\15modified\16finderinfomod\17changeowner\20xattrmod\21isfile\22isdir\23issymlink\24ownevent"
  27. static inline void
  28. sprintb(char *buf, unsigned short v, char *bits)
  29. {
  30. int i, any = 0;
  31. char c;
  32. char *bufp = buf;
  33. while ((i = *bits++)) {
  34. if (v & (1 << (i-1))) {
  35. if (any)
  36. *bufp++ = ',';
  37. any = 1;
  38. for (; (c = *bits) > 32; bits++)
  39. *bufp++ = c;
  40. } else
  41. for (; *bits > 32; bits++)
  42. ;
  43. }
  44. *bufp = '\0';
  45. }
  46. #endif /* fsevent_watch_common_h */