root/tools/testing/selftests/bpf/urandom_read.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. urandom_read
  2. main

   1 #include <stdio.h>
   2 #include <unistd.h>
   3 #include <sys/types.h>
   4 #include <sys/stat.h>
   5 #include <fcntl.h>
   6 #include <stdlib.h>
   7 
   8 #define BUF_SIZE 256
   9 
  10 static __attribute__((noinline))
  11 void urandom_read(int fd, int count)
  12 {
  13        char buf[BUF_SIZE];
  14        int i;
  15 
  16        for (i = 0; i < count; ++i)
  17                read(fd, buf, BUF_SIZE);
  18 }
  19 
  20 int main(int argc, char *argv[])
  21 {
  22         int fd = open("/dev/urandom", O_RDONLY);
  23         int count = 4;
  24 
  25         if (fd < 0)
  26                 return 1;
  27 
  28         if (argc == 2)
  29                 count = atoi(argv[1]);
  30 
  31         urandom_read(fd, count);
  32 
  33         close(fd);
  34         return 0;
  35 }

/* [<][>][^][v][top][bottom][index][help] */