blob: db781052758d3774b42cb891b86b09320e3d95d5 [file] [log] [blame]
Song Liu81f77fd2018-03-14 10:23:22 -07001#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
Song Liu13790d12018-05-07 10:50:49 -07009
Ivan Veceraf6827522019-03-15 21:04:14 +010010static __attribute__((noinline))
11void 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
Song Liu13790d12018-05-07 10:50:49 -070020int main(int argc, char *argv[])
Song Liu81f77fd2018-03-14 10:23:22 -070021{
22 int fd = open("/dev/urandom", O_RDONLY);
Song Liu13790d12018-05-07 10:50:49 -070023 int count = 4;
Song Liu81f77fd2018-03-14 10:23:22 -070024
25 if (fd < 0)
26 return 1;
Song Liu13790d12018-05-07 10:50:49 -070027
28 if (argc == 2)
29 count = atoi(argv[1]);
30
Ivan Veceraf6827522019-03-15 21:04:14 +010031 urandom_read(fd, count);
Song Liu81f77fd2018-03-14 10:23:22 -070032
33 close(fd);
34 return 0;
35}