From 821388c9011d8e5283454c3b2be72cdb7214a9c4 Mon Sep 17 00:00:00 2001 From: rswindell <> Date: Sat, 15 Oct 2005 02:25:35 +0000 Subject: [PATCH] Fix xp_randomize() build for *nix. --- src/xpdev/genwrap.c | 14 +++++++++++--- src/xpdev/genwrap.h | 5 +++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/xpdev/genwrap.c b/src/xpdev/genwrap.c index 560eb71c0a..bfa2f60dbd 100644 --- a/src/xpdev/genwrap.c +++ b/src/xpdev/genwrap.c @@ -236,9 +236,7 @@ char* strrev(char* str) /****************************************************************************/ unsigned DLLCALL xp_randomize(void) { - unsigned thread_id = (unsigned)GetCurrentThreadId(); - unsigned process_id = (unsigned)GetCurrentProcessId(); - unsigned seed = time(NULL) ^ BYTE_SWAP_INT(thread_id) ^ process_id; + unsigned seed=~0; #if defined(HAS_DEV_RANDOM) && defined(RANDOM_DEV) int rf; @@ -247,6 +245,16 @@ unsigned DLLCALL xp_randomize(void) read(rf, &seed, sizeof(seed)); close(rf); } +#else + unsigned curtime = (unsigned)time(NULL); + unsigned process_id = (unsigned)GetCurrentProcessId(); + + seed = curtime ^ BYTE_SWAP_INT(process_id); + + #if defined(_WIN32) || defined(GetCurrentThreadId) + seed ^= (unsigned)GetCurrentThreadId(); + #endif + #endif srand(seed); diff --git a/src/xpdev/genwrap.h b/src/xpdev/genwrap.h index 7bf052d80b..90770d894e 100644 --- a/src/xpdev/genwrap.h +++ b/src/xpdev/genwrap.h @@ -48,11 +48,16 @@ #include <sys/time.h> /* struct timeval */ #include <strings.h> /* strcasecmp() */ #include <unistd.h> /* usleep */ + + /* Simple Win32 function equivalents */ + #define GetCurrentProcessId() getpid() + #ifdef _THREAD_SAFE #include <pthread.h>/* Check for GNU PTH libs */ #ifdef _PTH_PTHREAD_H_ #include <pth.h> #endif + #define GetCurrentThreadId() pthread_self() #endif #elif defined(_WIN32) #include <process.h> /* getpid() */ -- GitLab