From c20ab7fdefb7765711cd7966ebb1caa114ffddc4 Mon Sep 17 00:00:00 2001 From: Ali Chraghi Date: Wed, 28 Sep 2022 20:21:33 +0330 Subject: [PATCH] std.c: fix incorrect return types Closes #12964 --- lib/std/c/darwin.zig | 4 ++-- lib/std/os/posix_spawn.zig | 22 ++++++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/std/c/darwin.zig b/lib/std/c/darwin.zig index e60d7f0763c9..54de5a32a476 100644 --- a/lib/std/c/darwin.zig +++ b/lib/std/c/darwin.zig @@ -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, diff --git a/lib/std/os/posix_spawn.zig b/lib/std/os/posix_spawn.zig index d36475df7f89..d82e6912f35f 100644 --- a/lib/std/os/posix_spawn.zig +++ b/lib/std/os/posix_spawn.zig @@ -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 { @@ -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 {