diff options
Diffstat (limited to 'lib/hcrypto/rand-unix.c')
-rw-r--r-- | lib/hcrypto/rand-unix.c | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/lib/hcrypto/rand-unix.c b/lib/hcrypto/rand-unix.c index c52155baaa81..2d6013eb348e 100644 --- a/lib/hcrypto/rand-unix.c +++ b/lib/hcrypto/rand-unix.c @@ -32,14 +32,11 @@ */ #include <config.h> +#include <roken.h> -#include <stdio.h> -#include <stdlib.h> #include <rand.h> #include <heim_threads.h> -#include <roken.h> - #include "randi.h" /* @@ -71,20 +68,33 @@ _hc_unix_device_fd(int flags, const char **fn) } static void -unix_seed(const void *indata, int size) +unix_seed(const void *p, int size) { + const unsigned char *indata = p; + ssize_t count; int fd; - if (size <= 0) + if (size < 0) + return; + else if (size == 0) return; - fd = _hc_unix_device_fd(O_WRONLY, NULL); + fd = _hc_unix_device_fd(O_RDONLY, NULL); if (fd < 0) return; - write(fd, indata, size); + while (size > 0) { + count = write(fd, indata, size); + if (count < 0 && errno == EINTR) + continue; + else if (count <= 0) { + close(fd); + return; + } + indata += count; + size -= count; + } close(fd); - } |