watcher.c 652 B

12345678910111213141516171819202122232425
  1. // clang-format off
  2. //go:build !nowatcher
  3. // clang-format on
  4. #include "_cgo_export.h"
  5. #include "wtr/watcher-c.h"
  6. void handle_event(struct wtr_watcher_event event, void *data) {
  7. go_handle_file_watcher_event((char *)event.path_name, event.effect_type,
  8. event.path_type, (uintptr_t)data);
  9. }
  10. uintptr_t start_new_watcher(char const *const path, uintptr_t data) {
  11. void *watcher = wtr_watcher_open(path, handle_event, (void *)data);
  12. if (watcher == NULL) {
  13. return 0;
  14. }
  15. return (uintptr_t)watcher;
  16. }
  17. int stop_watcher(uintptr_t watcher) {
  18. if (!wtr_watcher_close((void *)watcher)) {
  19. return 0;
  20. }
  21. return 1;
  22. }