diff options
Diffstat (limited to 'std/event/fs.zig')
| -rw-r--r-- | std/event/fs.zig | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/std/event/fs.zig b/std/event/fs.zig index 2ce3014178..1b8e1aa5dc 100644 --- a/std/event/fs.zig +++ b/std/event/fs.zig @@ -83,6 +83,7 @@ pub async fn pwritev(loop: *Loop, fd: os.FileHandle, data: []const []const u8, o switch (builtin.os) { builtin.Os.macosx, builtin.Os.linux, + builtin.Os.freebsd, => { const iovecs = try loop.allocator.alloc(os.posix.iovec_const, data.len); defer loop.allocator.free(iovecs); @@ -219,6 +220,7 @@ pub async fn preadv(loop: *Loop, fd: os.FileHandle, data: []const []u8, offset: switch (builtin.os) { builtin.Os.macosx, builtin.Os.linux, + builtin.Os.freebsd, => { const iovecs = try loop.allocator.alloc(os.posix.iovec, data.len); defer loop.allocator.free(iovecs); @@ -399,7 +401,7 @@ pub async fn openPosix( pub async fn openRead(loop: *Loop, path: []const u8) os.File.OpenError!os.FileHandle { switch (builtin.os) { - builtin.Os.macosx, builtin.Os.linux => { + builtin.Os.macosx, builtin.Os.linux, builtin.Os.freebsd => { const flags = posix.O_LARGEFILE | posix.O_RDONLY | posix.O_CLOEXEC; return await (async openPosix(loop, path, flags, os.File.default_mode) catch unreachable); }, @@ -427,6 +429,7 @@ pub async fn openWriteMode(loop: *Loop, path: []const u8, mode: os.File.Mode) os switch (builtin.os) { builtin.Os.macosx, builtin.Os.linux, + builtin.Os.freebsd, => { const flags = posix.O_LARGEFILE | posix.O_WRONLY | posix.O_CREAT | posix.O_CLOEXEC | posix.O_TRUNC; return await (async openPosix(loop, path, flags, os.File.default_mode) catch unreachable); @@ -449,7 +452,7 @@ pub async fn openReadWrite( mode: os.File.Mode, ) os.File.OpenError!os.FileHandle { switch (builtin.os) { - builtin.Os.macosx, builtin.Os.linux => { + builtin.Os.macosx, builtin.Os.linux, builtin.Os.freebsd => { const flags = posix.O_LARGEFILE | posix.O_RDWR | posix.O_CREAT | posix.O_CLOEXEC; return await (async openPosix(loop, path, flags, mode) catch unreachable); }, @@ -477,7 +480,7 @@ pub const CloseOperation = struct { os_data: OsData, const OsData = switch (builtin.os) { - builtin.Os.linux, builtin.Os.macosx => OsDataPosix, + builtin.Os.linux, builtin.Os.macosx, builtin.Os.freebsd => OsDataPosix, builtin.Os.windows => struct { handle: ?os.FileHandle, @@ -496,7 +499,7 @@ pub const CloseOperation = struct { self.* = CloseOperation{ .loop = loop, .os_data = switch (builtin.os) { - builtin.Os.linux, builtin.Os.macosx => initOsDataPosix(self), + builtin.Os.linux, builtin.Os.macosx, builtin.Os.freebsd => initOsDataPosix(self), builtin.Os.windows => OsData{ .handle = null }, else => @compileError("Unsupported OS"), }, @@ -525,6 +528,7 @@ pub const CloseOperation = struct { switch (builtin.os) { builtin.Os.linux, builtin.Os.macosx, + builtin.Os.freebsd, => { if (self.os_data.have_fd) { self.loop.posixFsRequest(&self.os_data.close_req_node); @@ -546,6 +550,7 @@ pub const CloseOperation = struct { switch (builtin.os) { builtin.Os.linux, builtin.Os.macosx, + builtin.Os.freebsd, => { self.os_data.close_req_node.data.msg.Close.fd = handle; self.os_data.have_fd = true; @@ -562,6 +567,7 @@ pub const CloseOperation = struct { switch (builtin.os) { builtin.Os.linux, builtin.Os.macosx, + builtin.Os.freebsd, => { self.os_data.have_fd = false; }, @@ -576,6 +582,7 @@ pub const CloseOperation = struct { switch (builtin.os) { builtin.Os.linux, builtin.Os.macosx, + builtin.Os.freebsd, => { assert(self.os_data.have_fd); return self.os_data.close_req_node.data.msg.Close.fd; @@ -599,6 +606,7 @@ pub async fn writeFileMode(loop: *Loop, path: []const u8, contents: []const u8, switch (builtin.os) { builtin.Os.linux, builtin.Os.macosx, + builtin.Os.freebsd, => return await (async writeFileModeThread(loop, path, contents, mode) catch unreachable), builtin.Os.windows => return await (async writeFileWindows(loop, path, contents) catch unreachable), else => @compileError("Unsupported OS"), @@ -704,7 +712,7 @@ pub fn Watch(comptime V: type) type { os_data: OsData, const OsData = switch (builtin.os) { - builtin.Os.macosx => struct { + builtin.Os.macosx, builtin.Os.freebsd => struct { file_table: FileTable, table_lock: event.Lock, @@ -793,7 +801,7 @@ pub fn Watch(comptime V: type) type { return self; }, - builtin.Os.macosx => { + builtin.Os.macosx, builtin.Os.freebsd => { const self = try loop.allocator.createOne(Self); errdefer loop.allocator.destroy(self); @@ -813,7 +821,7 @@ pub fn Watch(comptime V: type) type { /// All addFile calls and removeFile calls must have completed. pub fn destroy(self: *Self) void { switch (builtin.os) { - builtin.Os.macosx => { + builtin.Os.macosx, builtin.Os.freebsd => { // TODO we need to cancel the coroutines before destroying the lock self.os_data.table_lock.deinit(); var it = self.os_data.file_table.iterator(); @@ -855,14 +863,14 @@ pub fn Watch(comptime V: type) type { pub async fn addFile(self: *Self, file_path: []const u8, value: V) !?V { switch (builtin.os) { - builtin.Os.macosx => return await (async addFileMacosx(self, file_path, value) catch unreachable), + builtin.Os.macosx, builtin.Os.freebsd => return await (async addFileKEvent(self, file_path, value) catch unreachable), builtin.Os.linux => return await (async addFileLinux(self, file_path, value) catch unreachable), builtin.Os.windows => return await (async addFileWindows(self, file_path, value) catch unreachable), else => @compileError("Unsupported OS"), } } - async fn addFileMacosx(self: *Self, file_path: []const u8, value: V) !?V { + async fn addFileKEvent(self: *Self, file_path: []const u8, value: V) !?V { const resolved_path = try os.path.resolve(self.channel.loop.allocator, file_path); var resolved_path_consumed = false; defer if (!resolved_path_consumed) self.channel.loop.allocator.free(resolved_path); @@ -871,7 +879,10 @@ pub fn Watch(comptime V: type) type { var close_op_consumed = false; defer if (!close_op_consumed) close_op.finish(); - const flags = posix.O_SYMLINK | posix.O_EVTONLY; + const flags = switch (builtin.os) { + builtin.Os.macosx => posix.O_SYMLINK | posix.O_EVTONLY, + else => 0, + }; const mode = 0; const fd = try await (async openPosix(self.channel.loop, resolved_path, flags, mode) catch unreachable); close_op.setHandle(fd); |
