Commit 7e7ee160 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Simplify read_random_bytes.

parent c30f4ffc
...@@ -84,21 +84,24 @@ gettime(struct timeval *tv) ...@@ -84,21 +84,24 @@ gettime(struct timeval *tv)
/* If /dev/urandom doesn't exist, this will fail with ENOENT, which the /* If /dev/urandom doesn't exist, this will fail with ENOENT, which the
caller will deal with gracefully. */ caller will deal with gracefully. */
int ssize_t
read_random_bytes(void *buf, size_t len) read_random_bytes(void *buf, size_t len)
{ {
int fd; int fd;
int rc; size_t rc;
fd = open("/dev/urandom", O_RDONLY); fd = open("/dev/urandom", O_RDONLY);
if(fd < 0) { if(fd < 0) {
rc = -1; errno = ENOSYS;
} else { return -1;
}
rc = read(fd, buf, len); rc = read(fd, buf, len);
if(rc < 0 || (unsigned)rc < len) if(rc < len)
rc = -1; rc = -1;
close(fd); close(fd);
}
return rc; return rc;
} }
......
...@@ -77,6 +77,6 @@ int kernel_addresses(char *ifname, int ifindex, int ll, ...@@ -77,6 +77,6 @@ int kernel_addresses(char *ifname, int ifindex, int ll,
struct kernel_route *routes, int maxroutes); struct kernel_route *routes, int maxroutes);
int if_eui64(char *ifname, int ifindex, unsigned char *eui); int if_eui64(char *ifname, int ifindex, unsigned char *eui);
int gettime(struct timeval *tv); int gettime(struct timeval *tv);
int read_random_bytes(void *buf, size_t len); ssize_t read_random_bytes(void *buf, size_t len);
int kernel_older_than(const char *sysname, int version, int sub_version); int kernel_older_than(const char *sysname, int version, int sub_version);
int kernel_has_ipv6_subtrees(void); int kernel_has_ipv6_subtrees(void);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment