File:  [DVB] / dietlibc / lib / getentropy.c
Revision 1.3: download - view: text, annotated - select for diffs
Tue Feb 7 16:32:36 2017 UTC (7 years, 4 months ago) by leitner
Branches: MAIN
CVS tags: HEAD
use sys/random.h instead of unistd in lib/getentropy.c

#include <sys/random.h>
#include <errno.h>
#include <fcntl.h>

int getentropy(void* buf,size_t buflen) {
  int r;
  if (buflen>256) {
    errno=EIO;
    return -1;
  }
  r=getrandom(buf,buflen,GRND_NONBLOCK);
  if (r==-1 && errno==ENOSYS) {
    int fd=open("/dev/urandom",O_RDONLY);
    if (fd==-1) return -1;
    r=read(fd,buf,buflen);
    close(fd);
  }
  if (r<(int)buflen)
    return -1;
  return 0;
}

LinuxTV legacy CVS <linuxtv.org/cvs>