Skip to content

Commit

Permalink
Fallback to srand/rand if srandom/random are missing
Browse files Browse the repository at this point in the history
  • Loading branch information
scribam authored and dillof committed Jul 24, 2023
1 parent c788c92 commit 3a61d6a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions lib/zip_random_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 3a61d6a

Please sign in to comment.