This commit is contained in:
Mitchell Hashimoto
2022-10-23 11:39:21 -07:00
parent bc3762e85b
commit 34e1c96dd7

View File

@ -19,6 +19,12 @@ const c = switch (builtin.os.tag) {
}),
};
// https://github.com/ziglang/zig/issues/13277
// Once above is fixed, use `c.TIOCSCTTY`
const TIOCSCTTY = if (builtin.os.tag == .macos) 536900705 else c.TIOCSCTTY;
const TIOCSWINSZ = if (builtin.os.tag == .macos) 2148037735 else c.TIOCSWINSZ;
const TIOCGWINSZ = if (builtin.os.tag == .macos) 1074295912 else c.TIOCGWINSZ;
/// Redeclare this winsize struct so we can just use a Zig struct. This
/// layout should be correct on all tested platforms.
const winsize = extern struct {
@ -64,7 +70,7 @@ pub fn deinit(self: *Pty) void {
/// Return the size of the pty.
pub fn getSize(self: Pty) !winsize {
var ws: winsize = undefined;
if (c.ioctl(self.master, c.TIOCGWINSZ, @ptrToInt(&ws)) < 0)
if (c.ioctl(self.master, TIOCGWINSZ, @ptrToInt(&ws)) < 0)
return error.IoctlFailed;
return ws;
@ -72,7 +78,7 @@ pub fn getSize(self: Pty) !winsize {
/// Set the size of the pty.
pub fn setSize(self: Pty, size: winsize) !void {
if (c.ioctl(self.master, c.TIOCSWINSZ, @ptrToInt(&size)) < 0)
if (c.ioctl(self.master, TIOCSWINSZ, @ptrToInt(&size)) < 0)
return error.IoctlFailed;
}
@ -83,7 +89,7 @@ pub fn childPreExec(self: Pty) !void {
if (setsid() < 0) return error.ProcessGroupFailed;
// Set controlling terminal
if (c.ioctl(self.slave, c.TIOCSCTTY, @as(c_ulong, 0)) < 0)
if (c.ioctl(self.slave, TIOCSCTTY, @as(c_ulong, 0)) < 0)
return error.SetControllingTerminalFailed;
// Can close master/slave pair now