summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/Unix
diff options
context:
space:
mode:
authorNAKAMURA Takumi <geek4civic@gmail.com>2012-05-06 08:24:24 +0000
committerNAKAMURA Takumi <geek4civic@gmail.com>2012-05-06 08:24:24 +0000
commit7bec74112df4558fa7064c1dd3f993340b9d90bd (patch)
treedb933a6af7d36a5e1d97075896f65f284a05aa2d /llvm/lib/Support/Unix
parent54acb28882bc42d58a0c0b8fdd8501bdb88df6e0 (diff)
downloadbcm5719-llvm-7bec74112df4558fa7064c1dd3f993340b9d90bd.tar.gz
bcm5719-llvm-7bec74112df4558fa7064c1dd3f993340b9d90bd.zip
Unix/Process.inc: Give more useful random seed to srand. Workaround for PR12743.
llvm-svn: 156252
Diffstat (limited to 'llvm/lib/Support/Unix')
-rw-r--r--llvm/lib/Support/Unix/Process.inc15
1 files changed, 14 insertions, 1 deletions
diff --git a/llvm/lib/Support/Unix/Process.inc b/llvm/lib/Support/Unix/Process.inc
index de982625e96..dd855b0d3ff 100644
--- a/llvm/lib/Support/Unix/Process.inc
+++ b/llvm/lib/Support/Unix/Process.inc
@@ -298,11 +298,24 @@ const char *Process::ResetColor() {
return "\033[0m";
}
+#if !defined(HAVE_ARC4RANDOM)
+static unsigned GetRandomNumberSeed() {
+ unsigned seed = ::time(NULL); // FIXME: It might not provide unique seed.
+ FILE *RandomSource = ::fopen("/dev/urandom", "r");
+ if (RandomSource) {
+ ::fread((void *)&seed, sizeof(seed), 1, RandomSource);
+ ::fclose(RandomSource);
+ }
+ return seed;
+}
+#endif
+
unsigned llvm::sys::Process::GetRandomNumber() {
#if defined(HAVE_ARC4RANDOM)
return arc4random();
#else
- static int x = (::srand(::time(NULL)), 0);
+ static int x = (::srand(GetRandomNumberSeed()), 0);
+ (void)x;
return ::rand();
#endif
}
OpenPOWER on IntegriCloud