Mark McLoughlin wrote:
+static int
+qemudGenerateRandomBytes(unsigned char *buf,
+ int buflen)
+{
+ int fd;
+
+ if ((fd = open("/dev/urandom", O_RDONLY)) < 0)
+ return errno;
+
+ while (buflen > 0) {
+ int n;
+
+ if ((n = read(fd, buf, buflen)) <= 0) {
+ if (errno == EINTR)
+ continue;
+ close(fd);
+ return n < 0 ? errno : ENODATA;
+ }
+
+ buf += n;
+ buflen -= n;
+ }
+
+ close(fd);
+
+ return 0;
+}
This function would actually be quite useful as a generally available
function. In the remote patch I have added the following to configure.in:
dnl /dev/urandom
AC_CHECK_FILES([/dev/urandom])
and then in C code I can write:
#if HAVE__DEV_URANDOM /* NB double underscore */
// random blah blah
#else
// pseudorandom blah blah
#endif
Rich.
--
Emerging Technologies, Red Hat
http://et.redhat.com/~rjones/
64 Baker Street, London, W1U 7DF Mobile: +44 7866 314 421
"[Negative numbers] darken the very whole doctrines of the equations
and make dark of the things which are in their nature excessively
obvious and simple" (Francis Maseres FRS, mathematician, 1759)