File tree Expand file tree Collapse file tree 1 file changed +24
-2
lines changed Expand file tree Collapse file tree 1 file changed +24
-2
lines changed Original file line number Diff line number Diff line change 1515#include "qemu/guest-random.h"
1616#include "crypto/random.h"
1717//#include "sysemu/replay.h"
18-
18+ #include <stdlib.h>
19+ #include <string.h>
1920
2021#ifndef _MSC_VER
2122static __thread GRand * thread_rand ;
23+ #else
24+ static bool initialized = false;
2225#endif
2326static bool deterministic = true;
2427
25-
2628static int glib_random_bytes (void * buf , size_t len )
2729{
2830#ifndef _MSC_VER
@@ -43,6 +45,26 @@ static int glib_random_bytes(void *buf, size_t len)
4345 x = g_rand_int (rand );
4446 __builtin_memcpy (buf + i , & x , i - len );
4547 }
48+ #else
49+ uint32_t x ;
50+ size_t i ;
51+
52+ if (!initialized ) {
53+ if (deterministic ) {
54+ srand (0 );
55+ } else {
56+ srand (time (NULL ));
57+ }
58+
59+ for (i = 0 ; i + 4 <= len ; i += 4 ) {
60+ x = rand ();
61+ memcpy (buf + i , & x , 4 );
62+ }
63+ if (i < len ) {
64+ x = rand ();
65+ memcpy (buf + i , & x , i - len );
66+ }
67+ }
4668#endif
4769 return 0 ;
4870}
You can’t perform that action at this time.
0 commit comments