Skip to content
Snippets Groups Projects
Commit 821388c9 authored by rswindell's avatar rswindell
Browse files

Fix xp_randomize() build for *nix.

parent 5d6bde3a
Branches
Tags
No related merge requests found
......@@ -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);
......
......@@ -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() */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment