From 8d5043b32f8f6a6e569800bf9b872b901512a0c9 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Tue, 14 Nov 2023 17:52:48 +0100 Subject: [PATCH] Cygwin: rand(3): implement in terms of random(3) This makes rand(3) ISO C compliant and adds locking to avoid race conditions. Reported-by: Bruno Haible Fixes: 8a0efa53e4491 ("import newlib-2000-02-17 snapshot") Signed-off-by: Corinna Vinschen --- winsup/cygwin/random.cc | 8 ++++++++ winsup/cygwin/release/3.4.10 | 3 +++ 2 files changed, 11 insertions(+) diff --git a/winsup/cygwin/random.cc b/winsup/cygwin/random.cc index 51f5a6e96..ddba6fb94 100644 --- a/winsup/cygwin/random.cc +++ b/winsup/cygwin/random.cc @@ -293,6 +293,8 @@ srandom(unsigned x) __random_unlock(); } +EXPORT_ALIAS (srandom, srand) + /* * initstate: * @@ -481,4 +483,10 @@ random() return (r); } +int +rand() +{ + return ((int) random()); +} + } diff --git a/winsup/cygwin/release/3.4.10 b/winsup/cygwin/release/3.4.10 index 3bbbca381..758a6e071 100644 --- a/winsup/cygwin/release/3.4.10 +++ b/winsup/cygwin/release/3.4.10 @@ -15,3 +15,6 @@ Bug Fixes - Updates to profiler and gmondump: error display mechanics, buffer sizing, and output formatting. + +- Align behaviour of rand(3) to ISO C. + Adresses: https://cygwin.com/pipermail/cygwin/2023-November/254735.html -- 2.43.5