On Wed, 22 Apr 2020 20:42:54 -0300 Dan Gora <d...@adax.com> wrote: > + fd = open("/dev/urandom", O_RDONLY); > + if (fd < 0) { > + errno = ENODEV; > + return -1; > + } > + > + end = start + length; > + while (start < end) { > + bytes = read(fd, start, end - start); > + if (bytes < 0) {
You are overdoing the complexity here. More error handling is not better. 1. This should only be called once at startup EINTR is not an issue then 2. The amount requested is always returned when using urandom (see man page for random(4)) The O_NONBLOCK flag has no effect when opening /dev/urandom. When calling read(2) for the device /dev/urandom, reads of up to 256 bytes will return as many bytes as are requested and will not be interrupted by a signal handler. Reads with a buffer over this limit may return less than the requested number of bytes or fail with the error EINTR, if interrupted by a signal handler.