From 6968267966d7a239b4c07143afcd60bec024d0b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Love=20H=C3=B6rnquist=20=C3=85strand?= Date: Sat, 21 Oct 2006 21:09:14 +0000 Subject: [PATCH] (unix_bytes): read until the other side give us all or fail. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@18794 ec53bebd-3082-4978-b11e-865c3cabbd6b --- lib/des/rand-unix.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/des/rand-unix.c b/lib/des/rand-unix.c index ca53d141d..2f9aef963 100644 --- a/lib/des/rand-unix.c +++ b/lib/des/rand-unix.c @@ -87,7 +87,7 @@ unix_seed(const void *indata, int size) static int unix_bytes(unsigned char *outdata, int size) { - ssize_t ret; + ssize_t count; int fd; if (size <= 0) @@ -97,10 +97,18 @@ unix_bytes(unsigned char *outdata, int size) if (fd < 0) return 0; - ret = read(fd, outdata, size); + while (size > 0) { + count = read (fd, outdata, size); + if (count < 0 && errno == EINTR) + continue; + else if (count <= 0) { + close(fd); + return 0; + } + outdata += count; + size -= count; + } close(fd); - if (size != ret) - return 0; return 1; }