diff --git a/src/Command.zig b/src/Command.zig index ffc44423f..a810b16ce 100644 --- a/src/Command.zig +++ b/src/Command.zig @@ -193,11 +193,11 @@ fn startPosix(self: *Command, arena: Allocator) !void { } fn startWindows(self: *Command, arena: Allocator) !void { - const application_w = try std.unicode.utf8ToUtf16LeWithNull(arena, self.path); - const cwd_w = if (self.cwd) |cwd| try std.unicode.utf8ToUtf16LeWithNull(arena, cwd) else null; + const application_w = try std.unicode.utf8ToUtf16LeAllocZ(arena, self.path); + const cwd_w = if (self.cwd) |cwd| try std.unicode.utf8ToUtf16LeAllocZ(arena, cwd) else null; const command_line_w = if (self.args.len > 0) b: { const command_line = try windowsCreateCommandLine(arena, self.args); - break :b try std.unicode.utf8ToUtf16LeWithNull(arena, command_line); + break :b try std.unicode.utf8ToUtf16LeAllocZ(arena, command_line); } else null; const env_w = if (self.env) |env_map| try createWindowsEnvBlock(arena, env_map) else null; diff --git a/src/os/file.zig b/src/os/file.zig index 0f25503a2..240c936e0 100644 --- a/src/os/file.zig +++ b/src/os/file.zig @@ -10,7 +10,8 @@ pub const rlimit = if (@hasDecl(posix.system, "rlimit")) posix.rlimit else struc /// need to do this because each window consumes at least a handful of fds. /// This is extracted from the Zig compiler source code. pub fn fixMaxFiles() ?rlimit { - if (!@hasDecl(posix.system, "rlimit")) return null; + if (!@hasDecl(posix.system, "rlimit") or + posix.system.rlimit == void) return null; const old = posix.getrlimit(.NOFILE) catch { log.warn("failed to query file handle limit, may limit max windows", .{}); diff --git a/src/os/windows.zig b/src/os/windows.zig index 5140cd2a4..1853f4162 100644 --- a/src/os/windows.zig +++ b/src/os/windows.zig @@ -6,6 +6,8 @@ const windows = std.os.windows; pub const kernel32 = windows.kernel32; pub const unexpectedError = windows.unexpectedError; pub const OpenFile = windows.OpenFile; +pub const CloseHandle = windows.CloseHandle; +pub const GetCurrentProcessId = windows.GetCurrentProcessId; pub const SetHandleInformation = windows.SetHandleInformation; pub const DWORD = windows.DWORD; pub const FILE_ATTRIBUTE_NORMAL = windows.FILE_ATTRIBUTE_NORMAL; diff --git a/src/pty.zig b/src/pty.zig index 06d9bcd51..a36de9adc 100644 --- a/src/pty.zig +++ b/src/pty.zig @@ -275,7 +275,7 @@ const WindowsPty = struct { &pipe_path_buf, "\\\\.\\pipe\\LOCAL\\ghostty-pty-{d}-{d}", .{ - windows.kernel32.GetCurrentProcessId(), + windows.GetCurrentProcessId(), pipe_name_counter.fetchAdd(1, .monotonic), }, ) catch unreachable; @@ -308,7 +308,7 @@ const WindowsPty = struct { if (pty.in_pipe == windows.INVALID_HANDLE_VALUE) { return windows.unexpectedError(windows.kernel32.GetLastError()); } - errdefer _ = windows.kernel32.CloseHandle(pty.in_pipe); + errdefer _ = windows.CloseHandle(pty.in_pipe); var security_attributes_read = security_attributes; pty.in_pipe_pty = windows.kernel32.CreateFileW( @@ -323,7 +323,7 @@ const WindowsPty = struct { if (pty.in_pipe_pty == windows.INVALID_HANDLE_VALUE) { return windows.unexpectedError(windows.kernel32.GetLastError()); } - errdefer _ = windows.kernel32.CloseHandle(pty.in_pipe_pty); + errdefer _ = windows.CloseHandle(pty.in_pipe_pty); // The in_pipe needs to be created as a named pipe, since anonymous // pipes created with CreatePipe do not support overlapped operations, @@ -336,16 +336,16 @@ const WindowsPty = struct { // return windows.unexpectedError(windows.kernel32.GetLastError()); // } // errdefer { - // _ = windows.kernel32.CloseHandle(pty.in_pipe_pty); - // _ = windows.kernel32.CloseHandle(pty.in_pipe); + // _ = windows.CloseHandle(pty.in_pipe_pty); + // _ = windows.CloseHandle(pty.in_pipe); // } if (windows.exp.kernel32.CreatePipe(&pty.out_pipe, &pty.out_pipe_pty, null, 0) == 0) { return windows.unexpectedError(windows.kernel32.GetLastError()); } errdefer { - _ = windows.kernel32.CloseHandle(pty.out_pipe); - _ = windows.kernel32.CloseHandle(pty.out_pipe_pty); + _ = windows.CloseHandle(pty.out_pipe); + _ = windows.CloseHandle(pty.out_pipe_pty); } try windows.SetHandleInformation(pty.in_pipe, windows.HANDLE_FLAG_INHERIT, 0); @@ -367,10 +367,10 @@ const WindowsPty = struct { } pub fn deinit(self: *Pty) void { - _ = windows.kernel32.CloseHandle(self.in_pipe_pty); - _ = windows.kernel32.CloseHandle(self.in_pipe); - _ = windows.kernel32.CloseHandle(self.out_pipe_pty); - _ = windows.kernel32.CloseHandle(self.out_pipe); + _ = windows.CloseHandle(self.in_pipe_pty); + _ = windows.CloseHandle(self.in_pipe); + _ = windows.CloseHandle(self.out_pipe_pty); + _ = windows.CloseHandle(self.out_pipe); _ = windows.exp.kernel32.ClosePseudoConsole(self.pseudo_console); self.* = undefined; }