On 03/30/2011 07:46 PM, Eric Blake wrote:
I'm not sure whether block and character
special devices can usefully be set non-blocking

I believe at least /dev/random supports it:

#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
int main()
{
  char buf[256];
  int fd = open ("/dev/random", O_RDONLY | O_NONBLOCK);
  if (fd == -1) {
    perror ("/dev/random");
    exit (1);
  }
  alarm (5);
  while (read (fd, buf, 256) != -1 || errno != EAGAIN)
    ;
  puts ("works");
  exit (0);
}

Paolo

Reply via email to