Eric Bower
·
2026-07-26
1const builtin = @import("builtin");
2const std = @import("std");
3
4pub const c = switch (builtin.os.tag) {
5 .macos => @cImport({
6 @cInclude("sys/ioctl.h"); // ioctl and constants
7 @cInclude("termios.h");
8 @cInclude("stdlib.h");
9 @cInclude("unistd.h");
10 }),
11 .freebsd => @cImport({
12 @cInclude("termios.h"); // ioctl and constants
13 @cInclude("libutil.h"); // openpty()
14 @cInclude("stdlib.h");
15 @cInclude("unistd.h");
16 }),
17 else => @cImport({
18 @cInclude("sys/ioctl.h"); // ioctl and constants
19 @cInclude("pty.h");
20 @cInclude("stdlib.h");
21 @cInclude("unistd.h");
22 }),
23};
24
25// Manually declare forkpty for macOS since util.h is not available during cross-compilation
26pub const forkpty = if (builtin.os.tag == .macos)
27 struct {
28 extern "c" fn forkpty(master_fd: *c_int, name: ?[*:0]u8, termp: ?*const c.struct_termios, winp: ?*const c.struct_winsize) c_int;
29 }.forkpty
30else
31 c.forkpty;