Skip to content

Commit fefe618

Browse files
committed
Multi platform mechanism for getting error message from libc
1 parent 8d48ca3 commit fefe618

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/uucore/src/lib/features/process.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,13 @@ pub fn pid_is_alive(pid: i32) -> bool {
7272
if pid <= 0 {
7373
return true;
7474
}
75+
#[cfg(target_os = "linux")]
76+
let errno_ptr = unsafe { libc::__errno_location() };
7577

76-
unsafe { libc::kill(pid, 0) == 0 || *libc::__errno_location() != libc::ESRCH }
78+
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "netbsd"))]
79+
let errno_ptr = unsafe { libc::__error() };
80+
81+
unsafe { libc::kill(pid, 0) == 0 || *errno_ptr != libc::ESRCH }
7782
}
7883

7984
/// `getsid()` returns the session ID of the process with process ID pid.

0 commit comments

Comments
 (0)