summaryrefslogtreecommitdiff
path: root/src/lib
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
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 'src/lib')
-rw-r--r--src/lib/edje/edje_main.c2
-rw-r--r--src/lib/eina/eina_benchmark.h8
-rw-r--r--src/lib/eina/eina_main.c23
-rw-r--r--src/lib/elementary/elm_map.c2
-rw-r--r--src/lib/embryo/embryo_main.c2
5 files changed, 22 insertions, 15 deletions
diff --git a/src/lib/edje/edje_main.c b/src/lib/edje/edje_main.c
index 02bab59444..f75ca688ee 100644
--- a/src/lib/edje/edje_main.c
+++ b/src/lib/edje/edje_main.c
@@ -39,8 +39,6 @@ edje_init(void)
39 if (++_edje_init_count != 1) 39 if (++_edje_init_count != 1)
40 return _edje_init_count; 40 return _edje_init_count;
41 41
42 srand(time(NULL));
43
44 EINA_SAFETY_ON_FALSE_RETURN_VAL(eina_init(), --_edje_init_count); 42 EINA_SAFETY_ON_FALSE_RETURN_VAL(eina_init(), --_edje_init_count);
45 43
46 _edje_default_log_dom = eina_log_domain_register 44 _edje_default_log_dom = eina_log_domain_register
diff --git a/src/lib/eina/eina_benchmark.h b/src/lib/eina/eina_benchmark.h
index 38959a1306..b772132782 100644
--- a/src/lib/eina/eina_benchmark.h
+++ b/src/lib/eina/eina_benchmark.h
@@ -170,8 +170,6 @@
170 * char tmp[128]; 170 * char tmp[128];
171 * int i; 171 * int i;
172 * 172 *
173 * srand(time(NULL));
174 *
175 * for (i = 0; i < request; ++i) 173 * for (i = 0; i < request; ++i)
176 * eina_convert_itoa(rand(), tmp); 174 * eina_convert_itoa(rand(), tmp);
177 * } 175 * }
@@ -182,8 +180,6 @@
182 * char tmp[128]; 180 * char tmp[128];
183 * int i; 181 * int i;
184 * 182 *
185 * srand(time(NULL));
186 *
187 * for (i = 0; i < request; ++i) 183 * for (i = 0; i < request; ++i)
188 * eina_convert_xtoa(rand(), tmp); 184 * eina_convert_xtoa(rand(), tmp);
189 * } 185 * }
@@ -203,8 +199,6 @@
203 * int *data; 199 * int *data;
204 * int i; 200 * int i;
205 * 201 *
206 * srand(time(NULL));
207 *
208 * array = eina_array_new(64); 202 * array = eina_array_new(64);
209 * 203 *
210 * for (i = 0; i < request; ++i) 204 * for (i = 0; i < request; ++i)
@@ -228,8 +222,6 @@
228 * int *data; 222 * int *data;
229 * int i; 223 * int i;
230 * 224 *
231 * srand(time(NULL));
232 *
233 * for (i = 0; i < request; ++i) 225 * for (i = 0; i < request; ++i)
234 * { 226 * {
235 * data = (int *)malloc(sizeof(int)); 227 * data = (int *)malloc(sizeof(int));
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
diff --git a/src/lib/elementary/elm_map.c b/src/lib/elementary/elm_map.c
index 2924cb73dd..6d287fef5e 100644
--- a/src/lib/elementary/elm_map.c
+++ b/src/lib/elementary/elm_map.c
@@ -4170,8 +4170,6 @@ _elm_map_efl_canvas_group_group_add(Eo *obj, Elm_Map_Data *priv)
4170 // FIXME: Tile Provider is better to provide tile size! 4170 // FIXME: Tile Provider is better to provide tile size!
4171 priv->tsize = DEFAULT_TILE_SIZE; 4171 priv->tsize = DEFAULT_TILE_SIZE;
4172 4172
4173 srand(time(NULL));
4174
4175 priv->id = ((int)getpid() << 16) | id_num; 4173 priv->id = ((int)getpid() << 16) | id_num;
4176 id_num++; 4174 id_num++;
4177 _grid_all_create(priv); 4175 _grid_all_create(priv);
diff --git a/src/lib/embryo/embryo_main.c b/src/lib/embryo/embryo_main.c
index 452a272787..6bbac5891e 100644
--- a/src/lib/embryo/embryo_main.c
+++ b/src/lib/embryo/embryo_main.c
@@ -25,8 +25,6 @@ embryo_init(void)
25 if (++_embryo_init_count != 1) 25 if (++_embryo_init_count != 1)
26 return _embryo_init_count; 26 return _embryo_init_count;
27 27
28 srand(time(NULL));
29
30 if (!eina_init()) 28 if (!eina_init())
31 return --_embryo_init_count; 29 return --_embryo_init_count;
32 30