Song Liu | 81f77fd | 2018-03-14 10:23:22 -0700 | [diff] [blame] | 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 | ||||
Song Liu | 13790d1 | 2018-05-07 10:50:49 -0700 | [diff] [blame] | 9 | |
Ivan Vecera | f682752 | 2019-03-15 21:04:14 +0100 | [diff] [blame] | 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 | |||||
Song Liu | 13790d1 | 2018-05-07 10:50:49 -0700 | [diff] [blame] | 20 | int main(int argc, char *argv[]) |
Song Liu | 81f77fd | 2018-03-14 10:23:22 -0700 | [diff] [blame] | 21 | { |
22 | int fd = open("/dev/urandom", O_RDONLY); | ||||
Song Liu | 13790d1 | 2018-05-07 10:50:49 -0700 | [diff] [blame] | 23 | int count = 4; |
Song Liu | 81f77fd | 2018-03-14 10:23:22 -0700 | [diff] [blame] | 24 | |
25 | if (fd < 0) | ||||
26 | return 1; | ||||
Song Liu | 13790d1 | 2018-05-07 10:50:49 -0700 | [diff] [blame] | 27 | |
28 | if (argc == 2) | ||||
29 | count = atoi(argv[1]); | ||||
30 | |||||
Ivan Vecera | f682752 | 2019-03-15 21:04:14 +0100 | [diff] [blame] | 31 | urandom_read(fd, count); |
Song Liu | 81f77fd | 2018-03-14 10:23:22 -0700 | [diff] [blame] | 32 | |
33 | close(fd); | ||||
34 | return 0; | ||||
35 | } |