Skip to content

Commit

Permalink
os: don't return stack memory
Browse files Browse the repository at this point in the history
A regression from adcaff7
  • Loading branch information
mitchellh committed Dec 30, 2024
1 parent ef542c6 commit e9edd21
Showing 1 changed file with 25 additions and 29 deletions.
54 changes: 25 additions & 29 deletions src/os/open.zig
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,31 @@ pub fn open(
typ: Type,
url: []const u8,
) !void {
const cmd = try openCommand(alloc, typ, url);
const cmd: OpenCommand = switch (builtin.os.tag) {
.linux => .{ .child = std.process.Child.init(
&.{ "xdg-open", url },
alloc,
) },

.windows => .{ .child = std.process.Child.init(
&.{ "rundll32", "url.dll,FileProtocolHandler", url },
alloc,
) },

.macos => .{
.child = std.process.Child.init(
switch (typ) {
.text => &.{ "open", "-t", url },
.unknown => &.{ "open", url },
},
alloc,
),
.wait = true,
},

.ios => return error.Unimplemented,
else => @compileError("unsupported OS"),
};

var exe = cmd.child;
if (cmd.wait) {
Expand Down Expand Up @@ -53,31 +77,3 @@ const OpenCommand = struct {
child: std.process.Child,
wait: bool = false,
};

fn openCommand(alloc: Allocator, typ: Type, url: []const u8) !OpenCommand {
return switch (builtin.os.tag) {
.linux => .{ .child = std.process.Child.init(
&.{ "xdg-open", url },
alloc,
) },

.windows => .{ .child = std.process.Child.init(
&.{ "rundll32", "url.dll,FileProtocolHandler", url },
alloc,
) },

.macos => .{
.child = std.process.Child.init(
switch (typ) {
.text => &.{ "open", "-t", url },
.unknown => &.{ "open", url },
},
alloc,
),
.wait = true,
},

.ios => return error.Unimplemented,
else => @compileError("unsupported OS"),
};
}

0 comments on commit e9edd21

Please sign in to comment.