From 59b040258a6093fb518ee8bda724c78204bbb971 Mon Sep 17 00:00:00 2001
From: Peter Limkilde Svendsen <peter.limkilde@gmail.com>
Date: Tue, 23 Jun 2020 18:34:44 +0200
Subject: [PATCH] Rename lcg48 as rand48

---
 src/header/stdlib/mod.rs                      | 48 +++++++++----------
 src/header/stdlib/{lcg48.rs => rand48.rs}     |  0
 tests/Makefile                                |  2 +-
 .../stdlib/{lcg48.stderr => rand48.stderr}    |  0
 .../stdlib/{lcg48.stdout => rand48.stdout}    |  0
 tests/stdlib/{lcg48.c => rand48.c}            |  0
 6 files changed, 25 insertions(+), 25 deletions(-)
 rename src/header/stdlib/{lcg48.rs => rand48.rs} (100%)
 rename tests/expected/stdlib/{lcg48.stderr => rand48.stderr} (100%)
 rename tests/expected/stdlib/{lcg48.stdout => rand48.stdout} (100%)
 rename tests/stdlib/{lcg48.c => rand48.c} (100%)

diff --git a/src/header/stdlib/mod.rs b/src/header/stdlib/mod.rs
index 86892cb97..3501e083c 100644
--- a/src/header/stdlib/mod.rs
+++ b/src/header/stdlib/mod.rs
@@ -24,7 +24,7 @@ use crate::{
     platform::{self, types::*, Pal, Sys},
 };
 
-mod lcg48;
+mod rand48;
 mod random;
 mod sort;
 
@@ -245,8 +245,8 @@ pub extern "C" fn div(numer: c_int, denom: c_int) -> div_t {
 
 #[no_mangle]
 pub unsafe extern "C" fn drand48() -> c_double {
-    let new_xsubi_value = lcg48::generator_step(&mut lcg48::DEFAULT_XSUBI);
-    lcg48::f64_from_x(new_xsubi_value)
+    let new_xsubi_value = rand48::generator_step(&mut rand48::DEFAULT_XSUBI);
+    rand48::f64_from_x(new_xsubi_value)
 }
 
 // #[no_mangle]
@@ -261,8 +261,8 @@ pub extern "C" fn ecvt(
 
 #[no_mangle]
 pub unsafe extern "C" fn erand48(xsubi: *mut c_ushort) -> c_double {
-    let new_xsubi_value = lcg48::generator_step(&mut *(xsubi as *mut [c_ushort; 3]));
-    lcg48::f64_from_x(new_xsubi_value)
+    let new_xsubi_value = rand48::generator_step(&mut *(xsubi as *mut [c_ushort; 3]));
+    rand48::f64_from_x(new_xsubi_value)
 }
 
 #[no_mangle]
@@ -399,8 +399,8 @@ pub unsafe extern "C" fn initstate(seed: c_uint, state: *mut c_char, size: size_
 
 #[no_mangle]
 pub unsafe extern "C" fn jrand48(xsubi: *mut c_ushort) -> c_long {
-    let new_xsubi_value = lcg48::generator_step(&mut *(xsubi as *mut [c_ushort; 3]));
-    lcg48::i32_from_x(new_xsubi_value)
+    let new_xsubi_value = rand48::generator_step(&mut *(xsubi as *mut [c_ushort; 3]));
+    rand48::i32_from_x(new_xsubi_value)
 }
 
 #[no_mangle]
@@ -450,15 +450,15 @@ pub extern "C" fn labs(i: c_long) -> c_long {
 #[no_mangle]
 pub unsafe extern "C" fn lcong48(param: *mut c_ushort) {
     // Set DEFAULT_XSUBI buffer from elements 0-2
-    let xsubi_value = lcg48::u48_from_ushort_arr3(&*(param as *const [c_ushort; 3]));
-    lcg48::DEFAULT_XSUBI = lcg48::ushort_arr3_from_u48(xsubi_value);
+    let xsubi_value = rand48::u48_from_ushort_arr3(&*(param as *const [c_ushort; 3]));
+    rand48::DEFAULT_XSUBI = rand48::ushort_arr3_from_u48(xsubi_value);
 
     // Set multiplier from elements 3-5
-    lcg48::A = lcg48::u48_from_ushort_arr3(&*(param.offset(3) as *const [c_ushort; 3]));
+    rand48::A = rand48::u48_from_ushort_arr3(&*(param.offset(3) as *const [c_ushort; 3]));
 
     /* Set addend from element 6. Note that c_ushort may be more than 16
      * bits, thus the cast. */
-    lcg48::C = *param.offset(6) as u16;
+    rand48::C = *param.offset(6) as u16;
 }
 
 #[repr(C)]
@@ -496,8 +496,8 @@ pub extern "C" fn lldiv(numer: c_longlong, denom: c_longlong) -> lldiv_t {
 
 #[no_mangle]
 pub unsafe extern "C" fn lrand48() -> c_long {
-    let new_xsubi_value = lcg48::generator_step(&mut lcg48::DEFAULT_XSUBI);
-    lcg48::u31_from_x(new_xsubi_value)
+    let new_xsubi_value = rand48::generator_step(&mut rand48::DEFAULT_XSUBI);
+    rand48::u31_from_x(new_xsubi_value)
 }
 
 #[no_mangle]
@@ -650,14 +650,14 @@ pub extern "C" fn mkstemps(name: *mut c_char, suffix_len: c_int) -> c_int {
 
 #[no_mangle]
 pub unsafe extern "C" fn mrand48() -> c_long {
-    let new_xsubi_value = lcg48::generator_step(&mut lcg48::DEFAULT_XSUBI);
-    lcg48::i32_from_x(new_xsubi_value)
+    let new_xsubi_value = rand48::generator_step(&mut rand48::DEFAULT_XSUBI);
+    rand48::i32_from_x(new_xsubi_value)
 }
 
 #[no_mangle]
 pub unsafe extern "C" fn nrand48(xsubi: *mut c_ushort) -> c_long {
-    let new_xsubi_value = lcg48::generator_step(&mut *(xsubi as *mut [c_ushort; 3]));
-    lcg48::u31_from_x(new_xsubi_value)
+    let new_xsubi_value = rand48::generator_step(&mut *(xsubi as *mut [c_ushort; 3]));
+    rand48::u31_from_x(new_xsubi_value)
 }
 
 #[no_mangle]
@@ -824,17 +824,17 @@ pub unsafe extern "C" fn realpath(pathname: *const c_char, resolved: *mut c_char
 
 #[no_mangle]
 pub unsafe extern "C" fn seed48(seed16v: *mut c_ushort) -> *mut c_ushort {
-    lcg48::reset_a_and_c();
+    rand48::reset_a_and_c();
 
     // Stash current DEFAULT_XSUBI value in SEED48_XSUBI
-    lcg48::SEED48_XSUBI = lcg48::DEFAULT_XSUBI;
+    rand48::SEED48_XSUBI = rand48::DEFAULT_XSUBI;
 
     // Set DEFAULT_XSUBI from the argument provided
-    let xsubi_value = lcg48::u48_from_ushort_arr3(&*(seed16v as *const [c_ushort; 3]));
-    lcg48::DEFAULT_XSUBI = lcg48::ushort_arr3_from_u48(xsubi_value);
+    let xsubi_value = rand48::u48_from_ushort_arr3(&*(seed16v as *const [c_ushort; 3]));
+    rand48::DEFAULT_XSUBI = rand48::ushort_arr3_from_u48(xsubi_value);
 
     // Return the stashed value
-    lcg48::SEED48_XSUBI.as_mut_ptr()
+    rand48::SEED48_XSUBI.as_mut_ptr()
 }
 
 #[no_mangle]
@@ -928,13 +928,13 @@ pub unsafe extern "C" fn srand(seed: c_uint) {
 
 #[no_mangle]
 pub unsafe extern "C" fn srand48(seedval: c_long) {
-    lcg48::reset_a_and_c();
+    rand48::reset_a_and_c();
 
     /* Set the high 32 bits of the 48-bit X_i value to the lower 32 bits
      * of the input argument, and the lower 16 bits to 0x330e, as
      * specified in POSIX. */
     let xsubi_value = (u64::from(seedval as u32) << 16) | 0x330e;
-    lcg48::DEFAULT_XSUBI = lcg48::ushort_arr3_from_u48(xsubi_value);
+    rand48::DEFAULT_XSUBI = rand48::ushort_arr3_from_u48(xsubi_value);
 }
 
 #[no_mangle]
diff --git a/src/header/stdlib/lcg48.rs b/src/header/stdlib/rand48.rs
similarity index 100%
rename from src/header/stdlib/lcg48.rs
rename to src/header/stdlib/rand48.rs
diff --git a/tests/Makefile b/tests/Makefile
index 4efe68130..fde268103 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -53,9 +53,9 @@ EXPECT_NAMES=\
 	stdlib/atoi \
 	stdlib/div \
 	stdlib/env \
-	stdlib/lcg48 \
 	stdlib/mkostemps \
 	stdlib/rand \
+	stdlib/rand48 \
 	stdlib/random \
 	stdlib/strtod \
 	stdlib/strtol \
diff --git a/tests/expected/stdlib/lcg48.stderr b/tests/expected/stdlib/rand48.stderr
similarity index 100%
rename from tests/expected/stdlib/lcg48.stderr
rename to tests/expected/stdlib/rand48.stderr
diff --git a/tests/expected/stdlib/lcg48.stdout b/tests/expected/stdlib/rand48.stdout
similarity index 100%
rename from tests/expected/stdlib/lcg48.stdout
rename to tests/expected/stdlib/rand48.stdout
diff --git a/tests/stdlib/lcg48.c b/tests/stdlib/rand48.c
similarity index 100%
rename from tests/stdlib/lcg48.c
rename to tests/stdlib/rand48.c
-- 
GitLab