From c023fed8f0157fd644793018169b8e45b72e0b39 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 23 Apr 2022 14:15:54 -0700 Subject: [PATCH] compilation for macos works? --- src/Pty.zig | 17 +++++++++++++---- src/libuv/Embed.zig | 14 ++++++++------ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/Pty.zig b/src/Pty.zig index 18fdb6158..aa0e9e589 100644 --- a/src/Pty.zig +++ b/src/Pty.zig @@ -4,13 +4,19 @@ const Pty = @This(); const std = @import("std"); +const builtin = @import("builtin"); const testing = std.testing; const linux = std.os.linux; const fd_t = std.os.fd_t; const winsize = linux.winsize; -const c = @cImport({ - @cInclude("pty.h"); -}); +const c = switch (builtin.os.tag) { + .macos => @cImport({ + @cInclude("util.h"); + }), + else => @cImport({ + @cInclude("pty.h"); + }), +}; /// The file descriptors for the master and slave side of the pty. master: fd_t, @@ -18,6 +24,9 @@ slave: fd_t, /// Open a new PTY with the given initial size. pub fn open(size: winsize) !Pty { + // Need to copy so that it becomes non-const. + var sizeCopy = size; + var master_fd: fd_t = undefined; var slave_fd: fd_t = undefined; if (c.openpty( @@ -25,7 +34,7 @@ pub fn open(size: winsize) !Pty { &slave_fd, null, null, - @ptrCast([*c]const c.struct_winsize, &size), + @ptrCast([*c]c.struct_winsize, &sizeCopy), ) < 0) return error.OpenptyFailed; diff --git a/src/libuv/Embed.zig b/src/libuv/Embed.zig index fb2bec1fc..537cdbb83 100644 --- a/src/libuv/Embed.zig +++ b/src/libuv/Embed.zig @@ -103,14 +103,16 @@ fn threadMain(self: *Embed) void { // kqueue .macos, .dragonfly, .freebsd, .openbsd, .netbsd => { - // TODO: untested, probably some compile errors here - // or other issues, but this is roughly what we're trying - // to do. var ts: std.os.timespec = .{ - .tv_sec = timeout / 1000, - .tv_nsec = (timeout % 1000) * 1000, + .tv_sec = @divTrunc(timeout, 1000), + .tv_nsec = @mod(timeout, 1000) * 1000, + }; + + var ev: [0]std.os.Kevent = undefined; + _ = std.os.kevent(fd, &ev, &ev, &ts) catch |err| blk: { + log.err("kevent error: {}", .{err}); + break :blk 0; }; - while ((try std.os.kevent(fd, null, null, &ts)) == -1) {} }, else => @compileError("unsupported libuv Embed platform"),