aboutsummaryrefslogtreecommitdiff
path: root/lib/uuid/gen_uuid.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/uuid/gen_uuid.c')
-rw-r--r--lib/uuid/gen_uuid.c42
1 files changed, 15 insertions, 27 deletions
diff --git a/lib/uuid/gen_uuid.c b/lib/uuid/gen_uuid.c
index 89179b6e..2f028867 100644
--- a/lib/uuid/gen_uuid.c
+++ b/lib/uuid/gen_uuid.c
@@ -41,11 +41,6 @@
#include "config.h"
-#ifdef _WIN32
-#define _WIN32_WINNT 0x0500
-#include <windows.h>
-#define UUID MYUUID
-#endif
#include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
@@ -70,6 +65,9 @@
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
+#ifdef HAVE_SYS_RANDOM_H
+#include <sys/random.h>
+#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
@@ -114,27 +112,6 @@
THREAD_LOCAL unsigned short jrand_seed[3];
#endif
-#ifdef _WIN32
-#ifndef USE_MINGW
-static void gettimeofday (struct timeval *tv, void *dummy)
-{
- FILETIME ftime;
- uint64_t n;
-
- GetSystemTimeAsFileTime (&ftime);
- n = (((uint64_t) ftime.dwHighDateTime << 32)
- + (uint64_t) ftime.dwLowDateTime);
- if (n) {
- n /= 10;
- n -= ((369 * 365 + 89) * (uint64_t) 86400) * 1000000;
- }
-
- tv->tv_sec = n / 1000000;
- tv->tv_usec = n % 1000000;
-}
-#endif
-#endif
-
static int get_random_fd(void)
{
struct timeval tv;
@@ -174,10 +151,21 @@ static int get_random_fd(void)
*/
static void get_random_bytes(void *buf, int nbytes)
{
- int i, n = nbytes, fd = get_random_fd();
+ int i, n = nbytes, fd;
int lose_counter = 0;
unsigned char *cp = buf;
+#ifdef HAVE_GETRANDOM
+ i = getrandom(buf, nbytes, 0);
+ if (i == nbytes)
+ return;
+#endif
+#ifdef HAVE_GETENTROPY
+ if (getentropy(buf, nbytes) == 0)
+ return;
+#endif
+
+ fd = get_random_fd();
if (fd >= 0) {
while (n > 0) {
i = read(fd, cp, n);