1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

fixed partial reads in read_random()

This commit is contained in:
Steffen Vogel 2016-07-08 12:15:37 +02:00
parent 87eb7c13e2
commit fcd07748dd

View file

@ -304,21 +304,29 @@ void * memdup(const void *src, size_t bytes)
int read_random(char *buf, size_t len)
{
int ret, fd;
int fd;
fd = open("/dev/urandom", O_RDONLY);
if (fd < 0)
return -1;
ret = read(fd, buf, len);
if (ret != len)
ret = -1;
else
ret = 0;
ssize_t bytes, total = 0;
while (total < len) {
bytes = read(fd, buf + total, len - total);
if (bytes < 0)
goto out;
total += bytes;
}
close(fd);
return 0;
out:
close(fd);
return ret;
return -1;
}
void printb(void *mem, size_t len)