From 3a61d6a17b7fae2150f9f42122fb0fef664247c8 Mon Sep 17 00:00:00 2001 From: scribam Date: Mon, 24 Jul 2023 13:20:44 +0200 Subject: [PATCH] Fallback to srand/rand if srandom/random are missing --- CMakeLists.txt | 1 + lib/zip_random_unix.c | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 133dcad9a..cd27fd05f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -117,6 +117,7 @@ check_function_exists(getprogname HAVE_GETPROGNAME) check_symbol_exists(localtime_r time.h HAVE_LOCALTIME_R) check_symbol_exists(localtime_s time.h HAVE_LOCALTIME_S) check_function_exists(memcpy_s HAVE_MEMCPY_S) +check_function_exists(random HAVE_RANDOM) check_function_exists(setmode HAVE_SETMODE) check_symbol_exists(snprintf stdio.h HAVE_SNPRINTF) check_symbol_exists(snprintf_s stdio.h HAVE_SNPRINTF_S) diff --git a/lib/zip_random_unix.c b/lib/zip_random_unix.c index fd9a67d29..e8ed5bf70 100644 --- a/lib/zip_random_unix.c +++ b/lib/zip_random_unix.c @@ -93,12 +93,21 @@ zip_random_uint32(void) { return value; } +#ifdef HAVE_RANDOM if (!seeded) { srandom((unsigned int)time(NULL)); seeded = true; } return (zip_uint32_t)random(); +#else + if (!seeded) { + srand((unsigned int)time(NULL)); + seeded = true; + } + + return (zip_uint32_t)rand(); +#endif } #endif