Skip to content

Commit 3ee3a78

Browse files
committed
Use a const for getentropy(2)'s syscall number
Reported by Sebastien Marie.
1 parent a51b70b commit 3ee3a78

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/libstd/rand/os.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ mod imp {
208208
fn syscall(number: c_long, ...) -> c_long;
209209
}
210210

211+
const NR_GETENTROPY: libc::c_long = 7;
212+
211213
impl OsRng {
212214
/// Create a new `OsRng`.
213215
pub fn new() -> io::Result<OsRng> {
@@ -231,7 +233,9 @@ mod imp {
231233

232234
// getentropy(2) permits a maximum buffer size of 256 bytes
233235
for s in v.chunks_mut(256) {
234-
unsafe { ret = syscall(7, s.as_mut_ptr(), s.len()); }
236+
unsafe {
237+
ret = syscall(NR_GETENTROPY, s.as_mut_ptr(), s.len());
238+
}
235239
if ret == -1 {
236240
panic!("unexpected getentropy error: {}", errno());
237241
}

0 commit comments

Comments
 (0)