Skip to content

Commit

Permalink
Simplify fallback to srand/rand.
Browse files Browse the repository at this point in the history
  • Loading branch information
dillof committed Jul 24, 2023
1 parent 3a61d6a commit ecb4043
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions lib/zip_random_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ zip_secure_random(zip_uint8_t *buffer, zip_uint16_t length) {
#ifndef HAVE_RANDOM_UINT32
#include <stdlib.h>

#ifndef HAVE_RANDOM
#define srandom srand
#define random rand
#endif

zip_uint32_t
zip_random_uint32(void) {
static bool seeded = false;
Expand All @@ -93,21 +98,12 @@ 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 ecb4043

Please sign in to comment.