Skip to content

Commit

Permalink
std.c: fix incorrect return types
Browse files Browse the repository at this point in the history
  • Loading branch information
alichraghi committed Sep 30, 2022
1 parent 9a2f17f commit c20ab7f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/std/c/darwin.zig
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ pub extern "c" fn posix_memalign(memptr: *?*anyopaque, alignment: usize, size: u
pub const posix_spawnattr_t = *opaque {};
pub const posix_spawn_file_actions_t = *opaque {};
pub extern "c" fn posix_spawnattr_init(attr: *posix_spawnattr_t) c_int;
pub extern "c" fn posix_spawnattr_destroy(attr: *posix_spawnattr_t) void;
pub extern "c" fn posix_spawnattr_destroy(attr: *posix_spawnattr_t) c_int;
pub extern "c" fn posix_spawnattr_setflags(attr: *posix_spawnattr_t, flags: c_short) c_int;
pub extern "c" fn posix_spawnattr_getflags(attr: *const posix_spawnattr_t, flags: *c_short) c_int;
pub extern "c" fn posix_spawn_file_actions_init(actions: *posix_spawn_file_actions_t) c_int;
pub extern "c" fn posix_spawn_file_actions_destroy(actions: *posix_spawn_file_actions_t) void;
pub extern "c" fn posix_spawn_file_actions_destroy(actions: *posix_spawn_file_actions_t) c_int;
pub extern "c" fn posix_spawn_file_actions_addclose(actions: *posix_spawn_file_actions_t, filedes: fd_t) c_int;
pub extern "c" fn posix_spawn_file_actions_addopen(
actions: *posix_spawn_file_actions_t,
Expand Down
22 changes: 16 additions & 6 deletions lib/std/os/posix_spawn.zig
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,14 @@ const posix_spawn = if (builtin.target.isDarwin()) struct {
}
}

pub fn deinit(self: *Attr) void {
system.posix_spawnattr_destroy(&self.attr);
self.* = undefined;
pub fn deinit(self: *Attr) Error!void {
defer self.* = undefined;
switch (errno(system.posix_spawnattr_destroy(&self.attr))) {
.SUCCESS => {},
.NOMEM => return error.SystemResources,
.INVAL => unreachable,
else => |err| return unexpectedErrno(err),
}
}

pub fn get(self: Attr) Error!u16 {
Expand Down Expand Up @@ -82,9 +87,14 @@ const posix_spawn = if (builtin.target.isDarwin()) struct {
}
}

pub fn deinit(self: *Actions) void {
system.posix_spawn_file_actions_destroy(&self.actions);
self.* = undefined;
pub fn deinit(self: *Actions) Error!void {
defer self.* = undefined;
switch (errno(system.posix_spawn_file_actions_destroy(&self.attr))) {
.SUCCESS => {},
.NOMEM => return error.SystemResources,
.INVAL => unreachable,
else => |err| return unexpectedErrno(err),
}
}

pub fn open(self: *Actions, fd: fd_t, path: []const u8, flags: u32, mode: mode_t) Error!void {
Expand Down

0 comments on commit c20ab7f

Please sign in to comment.