about summary refs log tree commit diff
diff options
context:
space:
mode:
author王宇逸 <Strawberry_Str@hotmail.com>2025-03-07 15:59:49 +0800
committer王宇逸 <Strawberry_Str@hotmail.com>2025-03-10 21:23:32 +0800
commitc3051b1f5a6fa308cab85f37be446e7946e1f22e (patch)
tree21931e09d91fbb96805390ce49d9e6bf7ec5d627
parent268e73499652a27eeedd1d3e43430ebcdf1160f4 (diff)
downloadrust-c3051b1f5a6fa308cab85f37be446e7946e1f22e.tar.gz
rust-c3051b1f5a6fa308cab85f37be446e7946e1f22e.zip
Unify cygwin & horizon random impl
-rw-r--r--library/std/src/random.rs2
-rw-r--r--library/std/src/sys/random/cygwin.rs8
-rw-r--r--library/std/src/sys/random/getrandom.rs (renamed from library/std/src/sys/random/horizon.rs)0
-rw-r--r--library/std/src/sys/random/mod.rs11
4 files changed, 5 insertions, 16 deletions
diff --git a/library/std/src/random.rs b/library/std/src/random.rs
index 45f51dd37b0..e7d4ab81df0 100644
--- a/library/std/src/random.rs
+++ b/library/std/src/random.rs
@@ -37,7 +37,7 @@ use crate::sys::random as sys;
 /// Solaris                | [`arc4random_buf`](https://docs.oracle.com/cd/E88353_01/html/E37843/arc4random-3c.html)
 /// Vita                   | `arc4random_buf`
 /// Hermit                 | `read_entropy`
-/// Horizon                | `getrandom` shim
+/// Horizon, Cygwin        | `getrandom`
 /// AIX, Hurd, L4Re, QNX   | `/dev/urandom`
 /// Redox                  | `/scheme/rand`
 /// RTEMS                  | [`arc4random_buf`](https://docs.rtems.org/branches/master/bsp-howto/getentropy.html)
diff --git a/library/std/src/sys/random/cygwin.rs b/library/std/src/sys/random/cygwin.rs
deleted file mode 100644
index e6759c8a3ed..00000000000
--- a/library/std/src/sys/random/cygwin.rs
+++ /dev/null
@@ -1,8 +0,0 @@
-pub fn fill_bytes(mut bytes: &mut [u8]) {
-    while !bytes.is_empty() {
-        let ret =
-            unsafe { libc::getrandom(bytes.as_mut_ptr().cast(), bytes.len(), libc::GRND_NONBLOCK) };
-        assert!(ret != -1, "failed to generate random data");
-        bytes = &mut bytes[ret as usize..];
-    }
-}
diff --git a/library/std/src/sys/random/horizon.rs b/library/std/src/sys/random/getrandom.rs
index 0be2eae20a7..0be2eae20a7 100644
--- a/library/std/src/sys/random/horizon.rs
+++ b/library/std/src/sys/random/getrandom.rs
diff --git a/library/std/src/sys/random/mod.rs b/library/std/src/sys/random/mod.rs
index 2e5765b8a42..7f598c9e5cc 100644
--- a/library/std/src/sys/random/mod.rs
+++ b/library/std/src/sys/random/mod.rs
@@ -6,9 +6,6 @@ cfg_if::cfg_if! {
     } else if #[cfg(target_os = "windows")] {
         mod windows;
         pub use windows::fill_bytes;
-    } else if #[cfg(target_os = "cygwin")] {
-        mod cygwin;
-        pub use cygwin::fill_bytes;
     } else if #[cfg(target_vendor = "apple")] {
         mod apple;
         pub use apple::fill_bytes;
@@ -38,10 +35,10 @@ cfg_if::cfg_if! {
     } else if #[cfg(target_os = "hermit")] {
         mod hermit;
         pub use hermit::fill_bytes;
-    } else if #[cfg(target_os = "horizon")] {
-        // FIXME: add arc4random_buf to shim-3ds
-        mod horizon;
-        pub use horizon::fill_bytes;
+    } else if #[cfg(any(target_os = "horizon", target_os = "cygwin"))] {
+        // FIXME(horizon): add arc4random_buf to shim-3ds
+        mod getrandom;
+        pub use getrandom::fill_bytes;
     } else if #[cfg(any(
         target_os = "aix",
         target_os = "hurd",