repos / zmx

session persistence for terminal processes
git clone https://github.com/neurosnap/zmx.git

commit
659cf8e
parent
10c1e25
author
Tim Culverhouse
date
2025-10-13 09:51:35 -0400 EDT
support macOS and FreeBSD PTY functions (#1)

Replace Linux-specific PTY headers with platform-specific imports
to enable cross-platform compatibility. On macOS, use util.h for
openpty(). On FreeBSD, use libutil.h for openpty(). On Linux and
other platforms, continue using pty.h.

Remove unused utmp.h include that was never referenced in the code.

This change allows the daemon to compile and run on macOS and
FreeBSD in addition to Linux without requiring platform-specific
preprocessor directives or build configurations.

Amp-Thread-ID: https://ampcode.com/threads/T-15fd58fa-5673-40c5-87e1-3ea0057599ca

Co-authored-by: Amp <amp@ampcode.com>
1 files changed,  +18, -6
M src/daemon.zig
+18, -6
 1@@ -5,15 +5,27 @@ const xev = xevg.Dynamic;
 2 const clap = @import("clap");
 3 const config_mod = @import("config.zig");
 4 const protocol = @import("protocol.zig");
 5+const builtin = @import("builtin");
 6 
 7 const ghostty = @import("ghostty-vt");
 8 
 9-const c = @cImport({
10-    @cInclude("pty.h");
11-    @cInclude("utmp.h");
12-    @cInclude("stdlib.h");
13-    @cInclude("sys/ioctl.h");
14-});
15+const c = switch (builtin.os.tag) {
16+    .macos => @cImport({
17+        @cInclude("sys/ioctl.h"); // ioctl and constants
18+        @cInclude("util.h"); // openpty()
19+        @cInclude("stdlib.h");
20+    }),
21+    .freebsd => @cImport({
22+        @cInclude("termios.h"); // ioctl and constants
23+        @cInclude("libutil.h"); // openpty()
24+        @cInclude("stdlib.h");
25+    }),
26+    else => @cImport({
27+        @cInclude("sys/ioctl.h"); // ioctl and constants
28+        @cInclude("pty.h");
29+        @cInclude("stdlib.h");
30+    }),
31+};
32 
33 // Handler for processing VT sequences
34 const VTHandler = struct {