diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-19 09:26:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-19 09:26:03 +0000 |
commit | 9918693037dce8aa4bb6f08741b6812923486c18 (patch) | |
tree | 21d2b40bec7e6a7ea664acee056eb3d08e15a1cf /vendor/errno/src | |
parent | Releasing progress-linux version 1.75.0+dfsg1-5~progress7.99u1. (diff) | |
download | rustc-9918693037dce8aa4bb6f08741b6812923486c18.tar.xz rustc-9918693037dce8aa4bb6f08741b6812923486c18.zip |
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/errno/src')
-rw-r--r-- | vendor/errno/src/unix.rs | 28 | ||||
-rw-r--r-- | vendor/errno/src/wasi.rs | 8 |
2 files changed, 21 insertions, 15 deletions
diff --git a/vendor/errno/src/unix.rs b/vendor/errno/src/unix.rs index 86a35d9be..18951e424 100644 --- a/vendor/errno/src/unix.rs +++ b/vendor/errno/src/unix.rs @@ -13,7 +13,7 @@ // except according to those terms. use core::str; -use libc::{self, c_char, c_int, size_t, strlen}; +use libc::{self, c_int, size_t, strerror_r, strlen}; use crate::Errno; @@ -30,8 +30,13 @@ where { let mut buf = [0u8; 1024]; let c_str = unsafe { - if strerror_r(err.0, buf.as_mut_ptr() as *mut _, buf.len() as size_t) < 0 { - let fm_err = errno(); + let rc = strerror_r(err.0, buf.as_mut_ptr() as *mut _, buf.len() as size_t); + if rc != 0 { + // Handle negative return codes for compatibility with glibc < 2.13 + let fm_err = match rc < 0 { + true => errno(), + false => Errno(rc), + }; if fm_err != Errno(libc::ERANGE) { return callback(Err(fm_err)); } @@ -56,7 +61,13 @@ pub fn set_errno(Errno(errno): Errno) { extern "C" { #[cfg_attr( - any(target_os = "macos", target_os = "ios", target_os = "freebsd"), + any( + target_os = "macos", + target_os = "ios", + target_os = "tvos", + target_os = "watchos", + target_os = "freebsd" + ), link_name = "__error" )] #[cfg_attr( @@ -65,7 +76,8 @@ extern "C" { target_os = "netbsd", target_os = "bitrig", target_os = "android", - target_os = "espidf" + target_os = "espidf", + target_env = "newlib" ), link_name = "__errno" )] @@ -86,10 +98,4 @@ extern "C" { #[cfg_attr(target_os = "aix", link_name = "_Errno")] #[cfg_attr(target_os = "nto", link_name = "__get_errno_ptr")] fn errno_location() -> *mut c_int; - - #[cfg_attr( - any(target_os = "linux", target_os = "hurd"), - link_name = "__xpg_strerror_r" - )] - fn strerror_r(errnum: c_int, buf: *mut c_char, buflen: size_t) -> c_int; } diff --git a/vendor/errno/src/wasi.rs b/vendor/errno/src/wasi.rs index b18fa9b2c..404d7d519 100644 --- a/vendor/errno/src/wasi.rs +++ b/vendor/errno/src/wasi.rs @@ -13,7 +13,7 @@ // except according to those terms. use core::str; -use libc::{self, c_char, c_int, size_t, strlen}; +use libc::{self, c_int, size_t, strerror_r, strlen}; use crate::Errno; @@ -30,8 +30,9 @@ where { let mut buf = [0u8; 1024]; let c_str = unsafe { - if strerror_r(err.0, buf.as_mut_ptr() as *mut _, buf.len() as size_t) < 0 { - let fm_err = errno(); + let rc = strerror_r(err.0, buf.as_mut_ptr() as *mut _, buf.len() as size_t); + if rc != 0 { + let fm_err = Errno(rc); if fm_err != Errno(libc::ERANGE) { return callback(Err(fm_err)); } @@ -56,5 +57,4 @@ pub fn set_errno(Errno(new_errno): Errno) { extern "C" { fn __errno_location() -> *mut c_int; - fn strerror_r(errnum: c_int, buf: *mut c_char, buflen: size_t) -> c_int; } |