diff options
Diffstat (limited to 'src/file_watch.zig')
| -rw-r--r-- | src/file_watch.zig | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/file_watch.zig b/src/file_watch.zig index e3fe9963..9b41d146 100644 --- a/src/file_watch.zig +++ b/src/file_watch.zig @@ -5,9 +5,10 @@ //! is their generation. Large PDFs use metadata which changes for in-place and //! rename-over saves, avoiding a second whole-document allocation. //! -//! Two kernels, one transaction: inotify on linux, kqueue on macos. `init`, -//! `wait`, `stop`, `drain`, `markDir` and `unmarkDir` are the whole of that -//! difference, and nothing above them knows which one it is on. +//! Two kernels, one transaction: inotify on linux (and FreeBSD 15's, the +//! same events), kqueue on macos. `init`, `wait`, `stop`, `drain`, `markDir` +//! and `unmarkDir` are the whole of that difference, and nothing above them +//! knows which one it is on. const std = @import("std"); const builtin = @import("builtin"); const libc = std.c; @@ -81,7 +82,7 @@ pub const Table = [shader_slot + pardes.config.Runtime.Post.max]?Watch; /// empty and `reloadPane` returns false for every slot. The core then keeps its /// own record of what was asked and simply never gets a `file_changed`, which /// is what a host with no watcher has always done here. -pub const supported = builtin.os.tag == .linux or builtin.os.tag == .macos; +pub const supported = builtin.os.tag == .linux or builtin.os.tag == .freebsd or builtin.os.tag == .macos; /// The wake filter's `ident` on macos. `ident` is a directory descriptor for /// every other filter on this queue, and no descriptor is `maxInt(usize)`, so @@ -113,6 +114,8 @@ pub fn init(polled: bool) c_int { linux.IN.CLOEXEC | linux.IN.NONBLOCK else linux.IN.CLOEXEC), + // FreeBSD's IN_CLOEXEC and IN_NONBLOCK are its O_ flags. + .freebsd => return libc.inotify_init1(if (polled) 0x00100000 | 0x4 else 0x00100000), .macos => { const kq = libc.kqueue(); if (kq < 0) return -1; @@ -193,7 +196,7 @@ pub fn stop(fd: c_int) void { pub fn drain(fd: c_int) bool { if (fd < 0) return false; switch (builtin.os.tag) { - .linux => { + .linux, .freebsd => { var buf: [4096]u8 = undefined; var seen = false; while (libc.read(fd, &buf, buf.len) > 0) seen = true; @@ -227,7 +230,7 @@ pub fn drain(fd: c_int) bool { /// and inode, because each EVFILT_VNODE filter needs a descriptor of its own. fn markDir(fd: c_int, dir_z: [:0]const u8, watches: *const Table) c_int { switch (builtin.os.tag) { - .linux => { + .linux, .freebsd => { // CLOSE_WRITE coalesces one writer's writes; MOVED_TO and CREATE // cover rename-over and delete-then-recreate saves; DELETE and // MOVED_FROM a file going away, said at once (File.deleted), not @@ -366,7 +369,7 @@ fn unmark(fd: c_int, old: Watch, drop_dir: bool) void { } if (!drop_dir) return; switch (builtin.os.tag) { - .linux => _ = libc.inotify_rm_watch(fd, old.wd), + .linux, .freebsd => _ = libc.inotify_rm_watch(fd, old.wd), .macos => _ = libc.close(old.wd), else => {}, } |
