mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-08 02:24:33 +01:00
linux: Doc and check retval for no-fail pid calls
The switch from @bitCast() to @intCast() here safety-checks Linux's assertion that these 3 calls never return errors (negative values as pid_t). getppid() can legally return 0 if the parent is in a different pid namespace, but this is not an error.
This commit is contained in:
parent
04071d64bb
commit
6dbfba526f
1 changed files with 6 additions and 3 deletions
|
|
@ -1839,15 +1839,18 @@ pub fn setsid() usize {
|
|||
}
|
||||
|
||||
pub fn getpid() pid_t {
|
||||
return @bitCast(@as(u32, @truncate(syscall0(.getpid))));
|
||||
// Casts result to a pid_t, safety-checking >= 0, because getpid() cannot fail
|
||||
return @intCast(@as(u32, @truncate(syscall0(.getpid))));
|
||||
}
|
||||
|
||||
pub fn getppid() pid_t {
|
||||
return @bitCast(@as(u32, @truncate(syscall0(.getppid))));
|
||||
// Casts result to a pid_t, safety-checking >= 0, because getppid() cannot fail
|
||||
return @intCast(@as(u32, @truncate(syscall0(.getppid))));
|
||||
}
|
||||
|
||||
pub fn gettid() pid_t {
|
||||
return @bitCast(@as(u32, @truncate(syscall0(.gettid))));
|
||||
// Casts result to a pid_t, safety-checking >= 0, because gettid() cannot fail
|
||||
return @intCast(@as(u32, @truncate(syscall0(.gettid))));
|
||||
}
|
||||
|
||||
pub fn sigprocmask(flags: u32, noalias set: ?*const sigset_t, noalias oldset: ?*sigset_t) usize {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue