summaryrefslogtreecommitdiff
path: root/random.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-06-14 13:10:25 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-06-14 13:10:25 (GMT)
commita03ea378e79048ac188c8e4211ed2305e4643558 (patch)
treeff0d275b5770262fc9a3aa89028465eeb3cfae64 /random.c
parent93f7a11539dd1102a524b686d66a0aa5576be103 (diff)
prefer clock_gettime
* configure.ac: clock_gettime or gettimeofday must exist. * process.c (rb_clock_gettime): prefer clock_gettime over gettimeofday, as the latter is obsolete in SUSv4. * random.c (fill_random_seed): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63663 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'random.c')
-rw-r--r--random.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/random.c b/random.c
index 7a3b649..7165f3c 100644
--- a/random.c
+++ b/random.c
@@ -558,15 +558,24 @@ static void
fill_random_seed(uint32_t *seed, size_t cnt)
{
static int n = 0;
+#if defined HAVE_CLOCK_GETTIME
+ struct timespec tv;
+#elif defined HAVE_GETTIMEOFDAY
struct timeval tv;
+#endif
size_t len = cnt * sizeof(*seed);
memset(seed, 0, len);
fill_random_bytes(seed, len, FALSE);
+#if defined HAVE_CLOCK_GETTIME
+ clock_gettime(CLOCK_REALTIME, &tv);
+ seed[0] ^= tv.tv_nsec;
+#elif defined HAVE_GETTIMEOFDAY
gettimeofday(&tv, 0);
seed[0] ^= tv.tv_usec;
+#endif
seed[1] ^= (uint32_t)tv.tv_sec;
#if SIZEOF_TIME_T > SIZEOF_INT
seed[0] ^= (uint32_t)((time_t)tv.tv_sec >> SIZEOF_INT * CHAR_BIT);