summaryrefslogtreecommitdiffstats
path: root/polyp/random.c
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2006-01-05 22:51:37 +0000
committerPierre Ossman <ossman@cendio.se>2006-01-05 22:51:37 +0000
commit19d9fcbda8637099854f2d8147b402b4420d19f5 (patch)
tree993f0ebc9045bd893cd3039d0ae6277ee5806c05 /polyp/random.c
parent2f74bb9d437fc165695e1d4bb7516ca979962a49 (diff)
Port to Windows. This is mostly glue layers for the poor POSIX support
on Windows. A few notes * Only sockets behave somewhat like file descriptors in UNIX. * There are no fixed paths. Closes thing is environment variables that point to system directories. We also figure out where the binary/dll is located and use that as configuration directory. git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/ossman@418 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'polyp/random.c')
-rw-r--r--polyp/random.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/polyp/random.c b/polyp/random.c
index 456954a2..12f27bfd 100644
--- a/polyp/random.c
+++ b/polyp/random.c
@@ -19,6 +19,10 @@
USA.
***/
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
@@ -31,13 +35,16 @@
#include "util.h"
#include "log.h"
+#ifndef OS_IS_WIN32
#define RANDOM_DEVICE "/dev/urandom"
+#endif
void pa_random(void *ret_data, size_t length) {
int fd;
ssize_t r = 0;
assert(ret_data && length);
-
+
+#ifdef RANDOM_DEVICE
if ((fd = open(RANDOM_DEVICE, O_RDONLY)) >= 0) {
if ((r = pa_loop_read(fd, ret_data, length)) < 0 || (size_t) r != length)
@@ -45,17 +52,20 @@ void pa_random(void *ret_data, size_t length) {
close(fd);
}
+#endif
if ((size_t) r != length) {
uint8_t *p;
size_t l;
-
+
+#ifdef RANDOM_DEVICE
pa_log_warn(__FILE__": WARNING: Failed to open entropy device '"RANDOM_DEVICE"': %s"
", falling back to unsecure pseudo RNG.\n", strerror(errno));
+#endif
- srandom(time(NULL));
+ srand(time(NULL));
for (p = ret_data, l = length; l > 0; p++, l--)
- *p = (uint8_t) random();
+ *p = (uint8_t) rand();
}
}