Vendor dependencies for 0.3.0 release

This commit is contained in:
2025-09-27 10:29:08 -05:00
parent 0c8d39d483
commit 82ab7f317b
26803 changed files with 16134934 additions and 0 deletions

32
vendor/errno/src/hermit.rs vendored Normal file
View File

@@ -0,0 +1,32 @@
//! Implementation of `errno` functionality for RustyHermit.
//!
//! Currently, the error handling in RustyHermit isn't clearly
//! defined. At the current stage of RustyHermit, only a placeholder
//! is provided to be compatible to the classical errno interface.
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use crate::Errno;
pub fn with_description<F, T>(_err: Errno, callback: F) -> T
where
F: FnOnce(Result<&str, Errno>) -> T,
{
callback(Ok("unknown error"))
}
pub const STRERROR_NAME: &str = "strerror_r";
pub fn errno() -> Errno {
Errno(0)
}
pub fn set_errno(_: Errno) {}

160
vendor/errno/src/lib.rs vendored Normal file
View File

@@ -0,0 +1,160 @@
//! Cross-platform interface to the `errno` variable.
//!
//! # Examples
//! ```
//! use errno::{Errno, errno, set_errno};
//!
//! // Get the current value of errno
//! let e = errno();
//!
//! // Set the current value of errno
//! set_errno(e);
//!
//! // Extract the error code as an i32
//! let code = e.0;
//!
//! // Display a human-friendly error message
//! println!("Error {}: {}", code, e);
//! ```
#![cfg_attr(not(feature = "std"), no_std)]
#[cfg_attr(unix, path = "unix.rs")]
#[cfg_attr(windows, path = "windows.rs")]
#[cfg_attr(target_os = "wasi", path = "wasi.rs")]
#[cfg_attr(target_os = "hermit", path = "hermit.rs")]
mod sys;
use core::fmt;
#[cfg(feature = "std")]
use std::error::Error;
#[cfg(feature = "std")]
use std::io;
/// Wraps a platform-specific error code.
///
/// The `Display` instance maps the code to a human-readable string. It
/// calls [`strerror_r`][1] under POSIX, and [`FormatMessageW`][2] on
/// Windows.
///
/// [1]: http://pubs.opengroup.org/onlinepubs/009695399/functions/strerror.html
/// [2]: https://msdn.microsoft.com/en-us/library/windows/desktop/ms679351%28v=vs.85%29.aspx
#[derive(Copy, Clone, Eq, Ord, PartialEq, PartialOrd, Hash)]
pub struct Errno(pub i32);
impl fmt::Debug for Errno {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
sys::with_description(*self, |desc| {
fmt.debug_struct("Errno")
.field("code", &self.0)
.field("description", &desc.ok())
.finish()
})
}
}
impl fmt::Display for Errno {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
sys::with_description(*self, |desc| match desc {
Ok(desc) => fmt.write_str(desc),
Err(fm_err) => write!(
fmt,
"OS error {} ({} returned error {})",
self.0,
sys::STRERROR_NAME,
fm_err.0
),
})
}
}
impl From<Errno> for i32 {
fn from(e: Errno) -> Self {
e.0
}
}
#[cfg(feature = "std")]
impl Error for Errno {
// TODO: Remove when MSRV >= 1.27
#[allow(deprecated)]
fn description(&self) -> &str {
"system error"
}
}
#[cfg(feature = "std")]
impl From<Errno> for io::Error {
fn from(errno: Errno) -> Self {
io::Error::from_raw_os_error(errno.0)
}
}
/// Returns the platform-specific value of `errno`.
pub fn errno() -> Errno {
sys::errno()
}
/// Sets the platform-specific value of `errno`.
pub fn set_errno(err: Errno) {
sys::set_errno(err)
}
#[test]
fn it_works() {
let x = errno();
set_errno(x);
}
#[cfg(feature = "std")]
#[test]
fn it_works_with_to_string() {
let x = errno();
let _ = x.to_string();
}
#[cfg(feature = "std")]
#[test]
fn check_description() {
let expect = if cfg!(windows) {
"Incorrect function."
} else if cfg!(target_os = "illumos") {
"Not owner"
} else if cfg!(target_os = "wasi") || cfg!(target_os = "emscripten") {
"Argument list too long"
} else if cfg!(target_os = "haiku") {
"Operation not allowed"
} else if cfg!(target_os = "vxworks") {
"operation not permitted"
} else {
"Operation not permitted"
};
let errno_code = if cfg!(target_os = "haiku") {
-2147483633
} else if cfg!(target_os = "hurd") {
1073741825
} else {
1
};
set_errno(Errno(errno_code));
assert_eq!(errno().to_string(), expect);
assert_eq!(
format!("{:?}", errno()),
format!(
"Errno {{ code: {}, description: Some({:?}) }}",
errno_code, expect
)
);
}
#[cfg(feature = "std")]
#[test]
fn check_error_into_errno() {
const ERROR_CODE: i32 = 1;
let error = io::Error::from_raw_os_error(ERROR_CODE);
let new_error: io::Error = Errno(ERROR_CODE).into();
assert_eq!(error.kind(), new_error.kind());
}

35
vendor/errno/src/sys.rs vendored Normal file
View File

@@ -0,0 +1,35 @@
//! A default sys.rs for unrecognized targets.
//!
//! If lib.rs doesn't recognize the target, it defaults to using this file,
//! which issues an explanatory compile error.
// If there is no OS, there's no `errno` or equivalent defined.
#[cfg(any(target_os = "unknown", target_os = "none"))]
compile_error!("The target OS is \"unknown\" or \"none\", so it's unsupported by the errno crate.");
// If there is an OS, support may be added.
#[cfg(not(any(target_os = "unknown", target_os = "none")))]
compile_error!("The target OS is not yet supported in the errno crate.");
// The following define the functions of the normal implementations
// so that the user doesn't see uninteresting errors after the
// errors above.
use crate::Errno;
pub fn with_description<F, T>(_err: Errno, _callback: F) -> T
where
F: FnOnce(Result<&str, Errno>) -> T,
{
unreachable!()
}
pub const STRERROR_NAME: &str = "";
pub fn errno() -> Errno {
unreachable!()
}
pub fn set_errno(_: Errno) {
unreachable!()
}

104
vendor/errno/src/unix.rs vendored Normal file
View File

@@ -0,0 +1,104 @@
//! Implementation of `errno` functionality for Unix systems.
//!
//! Adapted from `src/libstd/sys/unix/os.rs` in the Rust distribution.
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use core::str;
use libc::{self, c_int, size_t, strerror_r, strlen};
use crate::Errno;
fn from_utf8_lossy(input: &[u8]) -> &str {
match str::from_utf8(input) {
Ok(valid) => valid,
Err(error) => unsafe { str::from_utf8_unchecked(&input[..error.valid_up_to()]) },
}
}
pub fn with_description<F, T>(err: Errno, callback: F) -> T
where
F: FnOnce(Result<&str, Errno>) -> T,
{
let mut buf = [0u8; 1024];
let c_str = unsafe {
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));
}
}
let c_str_len = strlen(buf.as_ptr() as *const _);
&buf[..c_str_len]
};
callback(Ok(from_utf8_lossy(c_str)))
}
pub const STRERROR_NAME: &str = "strerror_r";
pub fn errno() -> Errno {
unsafe { Errno(*errno_location()) }
}
pub fn set_errno(Errno(errno): Errno) {
unsafe {
*errno_location() = errno;
}
}
extern "C" {
#[cfg_attr(
any(
target_os = "macos",
target_os = "ios",
target_os = "tvos",
target_os = "watchos",
target_os = "visionos",
target_os = "freebsd"
),
link_name = "__error"
)]
#[cfg_attr(
any(
target_os = "openbsd",
target_os = "netbsd",
target_os = "android",
target_os = "espidf",
target_os = "vxworks",
target_os = "cygwin",
target_env = "newlib"
),
link_name = "__errno"
)]
#[cfg_attr(
any(target_os = "solaris", target_os = "illumos"),
link_name = "___errno"
)]
#[cfg_attr(target_os = "haiku", link_name = "_errnop")]
#[cfg_attr(
any(
target_os = "linux",
target_os = "hurd",
target_os = "redox",
target_os = "dragonfly",
target_os = "emscripten",
),
link_name = "__errno_location"
)]
#[cfg_attr(target_os = "aix", link_name = "_Errno")]
#[cfg_attr(target_os = "nto", link_name = "__get_errno_ptr")]
fn errno_location() -> *mut c_int;
}

60
vendor/errno/src/wasi.rs vendored Normal file
View File

@@ -0,0 +1,60 @@
//! Implementation of `errno` functionality for WASI.
//!
//! Adapted from `unix.rs`.
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use core::str;
use libc::{self, c_int, size_t, strerror_r, strlen};
use crate::Errno;
fn from_utf8_lossy(input: &[u8]) -> &str {
match str::from_utf8(input) {
Ok(valid) => valid,
Err(error) => unsafe { str::from_utf8_unchecked(&input[..error.valid_up_to()]) },
}
}
pub fn with_description<F, T>(err: Errno, callback: F) -> T
where
F: FnOnce(Result<&str, Errno>) -> T,
{
let mut buf = [0u8; 1024];
let c_str = unsafe {
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));
}
}
let c_str_len = strlen(buf.as_ptr() as *const _);
&buf[..c_str_len]
};
callback(Ok(from_utf8_lossy(c_str)))
}
pub const STRERROR_NAME: &str = "strerror_r";
pub fn errno() -> Errno {
unsafe { Errno(*__errno_location()) }
}
pub fn set_errno(Errno(new_errno): Errno) {
unsafe {
*__errno_location() = new_errno;
}
}
extern "C" {
fn __errno_location() -> *mut c_int;
}

81
vendor/errno/src/windows.rs vendored Normal file
View File

@@ -0,0 +1,81 @@
//! Implementation of `errno` functionality for Windows.
//!
//! Adapted from `src/libstd/sys/windows/os.rs` in the Rust distribution.
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use core::char::{self, REPLACEMENT_CHARACTER};
use core::ptr;
use core::str;
use windows_sys::Win32::Foundation::{GetLastError, SetLastError, WIN32_ERROR};
use windows_sys::Win32::System::Diagnostics::Debug::{
FormatMessageW, FORMAT_MESSAGE_FROM_SYSTEM, FORMAT_MESSAGE_IGNORE_INSERTS,
};
use crate::Errno;
fn from_utf16_lossy<'a>(input: &[u16], output: &'a mut [u8]) -> &'a str {
let mut output_len = 0;
for c in char::decode_utf16(input.iter().copied().take_while(|&x| x != 0))
.map(|x| x.unwrap_or(REPLACEMENT_CHARACTER))
{
let c_len = c.len_utf8();
if c_len > output.len() - output_len {
break;
}
c.encode_utf8(&mut output[output_len..]);
output_len += c_len;
}
unsafe { str::from_utf8_unchecked(&output[..output_len]) }
}
pub fn with_description<F, T>(err: Errno, callback: F) -> T
where
F: FnOnce(Result<&str, Errno>) -> T,
{
// This value is calculated from the macro
// MAKELANGID(LANG_SYSTEM_DEFAULT, SUBLANG_SYS_DEFAULT)
let lang_id = 0x0800_u32;
let mut buf = [0u16; 2048];
unsafe {
let res = FormatMessageW(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
ptr::null_mut(),
err.0 as u32,
lang_id,
buf.as_mut_ptr(),
buf.len() as u32,
ptr::null_mut(),
);
if res == 0 {
// Sometimes FormatMessageW can fail e.g. system doesn't like lang_id
let fm_err = errno();
return callback(Err(fm_err));
}
let mut msg = [0u8; 2048];
let msg = from_utf16_lossy(&buf[..res as usize], &mut msg[..]);
// Trim trailing CRLF inserted by FormatMessageW
callback(Ok(msg.trim_end()))
}
}
pub const STRERROR_NAME: &str = "FormatMessageW";
pub fn errno() -> Errno {
unsafe { Errno(GetLastError() as i32) }
}
pub fn set_errno(Errno(errno): Errno) {
unsafe { SetLastError(errno as WIN32_ERROR) }
}