mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 16:56:09 +03:00
os: add internal_os.pipe for cross-platfor pipe
This commit is contained in:
@ -9,6 +9,7 @@ pub usingnamespace @import("homedir.zig");
|
||||
pub usingnamespace @import("locale.zig");
|
||||
pub usingnamespace @import("macos_version.zig");
|
||||
pub usingnamespace @import("mouse.zig");
|
||||
pub usingnamespace @import("pipe.zig");
|
||||
pub usingnamespace @import("resourcesdir.zig");
|
||||
pub const TempDir = @import("TempDir.zig");
|
||||
pub const passwd = @import("passwd.zig");
|
||||
|
19
src/os/pipe.zig
Normal file
19
src/os/pipe.zig
Normal file
@ -0,0 +1,19 @@
|
||||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const windows = @import("windows.zig");
|
||||
|
||||
/// pipe() that works on Windows and POSIX.
|
||||
pub fn pipe() ![2]std.os.fd_t {
|
||||
switch (builtin.os.tag) {
|
||||
else => return try std.os.pipe(),
|
||||
.windows => {
|
||||
var read: windows.HANDLE = undefined;
|
||||
var write: windows.HANDLE = undefined;
|
||||
if (windows.exp.kernel32.CreatePipe(&read, &write, null, 0) == 0) {
|
||||
return windows.unexpectedError(windows.kernel32.GetLastError());
|
||||
}
|
||||
|
||||
return .{ read, write };
|
||||
},
|
||||
}
|
||||
}
|
@ -194,15 +194,7 @@ pub fn threadEnter(self: *Exec, thread: *termio.Thread) !ThreadData {
|
||||
|
||||
// Create our pipe that we'll use to kill our read thread.
|
||||
// pipe[0] is the read end, pipe[1] is the write end.
|
||||
const pipe = if (builtin.os.tag == .windows) pipe: {
|
||||
var read: windows.HANDLE = undefined;
|
||||
var write: windows.HANDLE = undefined;
|
||||
if (windows.exp.kernel32.CreatePipe(&read, &write, null, 0) == 0) {
|
||||
return windows.unexpectedError(windows.kernel32.GetLastError());
|
||||
}
|
||||
|
||||
break :pipe .{ read, write };
|
||||
} else try std.os.pipe();
|
||||
const pipe = try internal_os.pipe();
|
||||
errdefer std.os.close(pipe[0]);
|
||||
errdefer std.os.close(pipe[1]);
|
||||
|
||||
@ -1140,7 +1132,6 @@ const ReadThread = struct {
|
||||
}
|
||||
}
|
||||
|
||||
/// The main entrypoint for the thread.
|
||||
fn threadMainWindows(fd: std.os.fd_t, ev: *EventData, quit: std.os.fd_t) void {
|
||||
// Always close our end of the pipe when we exit.
|
||||
defer std.os.close(quit);
|
||||
@ -1154,6 +1145,7 @@ const ReadThread = struct {
|
||||
switch (err) {
|
||||
// Check for a quit signal
|
||||
.OPERATION_ABORTED => break,
|
||||
|
||||
else => {
|
||||
log.err("io reader error err={}", .{err});
|
||||
unreachable;
|
||||
|
Reference in New Issue
Block a user