From 9280fb8d6daeab948fac6656397c928493f5fd05 Mon Sep 17 00:00:00 2001 From: Anton Livaja Date: Mon, 23 Sep 2024 14:00:23 -0400 Subject: [PATCH] fix: uncomment code to make lib functional until we refactor --- src/lib.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index be7fd5f..9fb3a04 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,15 +13,26 @@ fn fakerand_value() -> Option { *FAKERAND.get_or_init(|| env::var("FAKERAND").ok().and_then(|v| v.parse().ok())) } -/* #[no_mangle] pub extern "C" fn rand() -> c_int { - println!("rand() called"); + if let Some(fakerand) = fakerand_value() { println!("rand() value {}", fakerand); return fakerand; } + // match fakerand_value() { + // Some(n) => return n, + // None => { + // eprint!("fakerand loaded but unable to generate fake rand"); + // unsafe { + // let errno = libc::__errno_location(); + // *errno = libc::EINVAL; + // } + // return -1; + // } + // }; + unsafe { let symbol = dlsym(RTLD_NEXT, "rand\0".as_ptr() as *const _); @@ -34,7 +45,6 @@ pub extern "C" fn rand() -> c_int { } } } -*/ #[inline(always)] unsafe fn copy_slice_to_ptr(slice: &[u8], buf: *mut c_void, buf_size: usize) { @@ -129,7 +139,6 @@ pub extern "C" fn read(fd: c_int, buf: *mut c_void, count: usize) -> ssize_t { original_read(fd, buf, count) } -/* /// # Safety /// /// Checked by caller. This function may result in undefined behavior if buflen is longer than the @@ -173,7 +182,6 @@ pub extern "C" fn RAND_bytes(buf: *mut c_uchar, num: c_int) -> c_int { } } } -*/ #[cfg(test)] mod tests {