summaryrefslogtreecommitdiff
path: root/src/lib/eina/eina_main.c
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2020-10-03 20:46:50 +0100
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2020-10-03 20:46:50 +0100
commit42c123d1d7b4b5fa1251b3ae7768912f480d36a3 (patch)
tree50d320ae44fde2d6d547cf4e74a547c7ae8c33b0 /src/lib/eina/eina_main.c
parentde5ac3287002f21fb13f97ba635f6962664e3ebc (diff)
singularize srand in eina_init - only once in one place
simplify down to having a single srand() in eina_init and use urandom if it works and is there - if not, time(NULL) will do. it's the best we can...
Diffstat (limited to '')
-rw-r--r--src/lib/eina/eina_main.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/lib/eina/eina_main.c b/src/lib/eina/eina_main.c
index 47dd80a898..9549ab96c3 100644
--- a/src/lib/eina/eina_main.c
+++ b/src/lib/eina/eina_main.c
@@ -30,6 +30,14 @@
30# include <unistd.h> 30# include <unistd.h>
31#endif 31#endif
32 32
33#ifndef _WIN32
34# ifdef HAVE_SYS_TYPES_H
35# include <sys/types.h>
36# endif
37# include <sys/stat.h>
38# include <fcntl.h>
39#endif
40
33#ifdef HAVE_MCHECK_H 41#ifdef HAVE_MCHECK_H
34# ifdef HAVE_MTRACE 42# ifdef HAVE_MTRACE
35# define MT 1 43# define MT 1
@@ -283,7 +291,20 @@ eina_init(void)
283 if (EINA_LIKELY(_eina_main_count > 0)) 291 if (EINA_LIKELY(_eina_main_count > 0))
284 return ++_eina_main_count; 292 return ++_eina_main_count;
285 293
286 srand(time(NULL)); 294#ifdef _WIN32
295#else
296 int fd = open("/dev/urandom", O_RDONLY);
297 if (fd >= 0)
298 {
299 unsigned int val;
300
301 if (read(fd, &val, sizeof(val)) == sizeof(val)) srand(val);
302 else srand(time(NULL));
303 close(fd);
304 }
305 else
306#endif
307 srand(time(NULL));
287 while (eina_seed == 0) 308 while (eina_seed == 0)
288 eina_seed = rand(); 309 eina_seed = rand();
289 310