about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Carlier <devnexen@gmail.com>2024-03-12 00:33:48 +0000
committerDavid Carlier <devnexen@gmail.com>2024-03-12 00:54:57 +0000
commit6a16638de6449fd30b804e55f3cc2c142e32f55e (patch)
tree11f8c3e6d51e319ca13abb1e5462daf1f4d6ddea
parent4a0cc881dcc4d800f10672747f61a94377ff6662 (diff)
downloadrust-6a16638de6449fd30b804e55f3cc2c142e32f55e.tar.gz
rust-6a16638de6449fd30b804e55f3cc2c142e32f55e.zip
std::rand: fix dragonflybsd after #121942.
-rw-r--r--library/std/src/sys/pal/unix/rand.rs20
1 files changed, 13 insertions, 7 deletions
diff --git a/library/std/src/sys/pal/unix/rand.rs b/library/std/src/sys/pal/unix/rand.rs
index c9ed6825f6c..d52c3254e5e 100644
--- a/library/std/src/sys/pal/unix/rand.rs
+++ b/library/std/src/sys/pal/unix/rand.rs
@@ -62,17 +62,23 @@ mod imp {
         unsafe { getrandom(buf.as_mut_ptr().cast(), buf.len(), libc::GRND_NONBLOCK) }
     }
 
-    #[cfg(any(
-        target_os = "espidf",
-        target_os = "horizon",
-        target_os = "freebsd",
-        target_os = "dragonfly",
-        netbsd10
-    ))]
+    #[cfg(any(target_os = "espidf", target_os = "horizon", target_os = "freebsd", netbsd10))]
     fn getrandom(buf: &mut [u8]) -> libc::ssize_t {
         unsafe { libc::getrandom(buf.as_mut_ptr().cast(), buf.len(), 0) }
     }
 
+    #[cfg(target_os = "dragonfly")]
+    fn getrandom(buf: &mut [u8]) -> libc::ssize_t {
+        extern "C" {
+            fn getrandom(
+                buf: *mut libc::c_void,
+                buflen: libc::size_t,
+                flags: libc::c_uint,
+            ) -> libc::ssize_t;
+        }
+        unsafe { getrandom(buf.as_mut_ptr().cast(), buf.len(), 0) }
+    }
+
     #[cfg(not(any(
         target_os = "linux",
         target_os = "android",