compilation for macos works?

This commit is contained in:
Mitchell Hashimoto
2022-04-23 14:15:54 -07:00
parent 8b0d914ddc
commit c023fed8f0
2 changed files with 21 additions and 10 deletions

View File

@ -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({
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;

View File

@ -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"),