2018-03-15 01:23:22 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#define BUF_SIZE 256
|
2018-05-08 01:50:49 +08:00
|
|
|
|
2019-03-16 04:04:14 +08:00
|
|
|
static __attribute__((noinline))
|
|
|
|
void urandom_read(int fd, int count)
|
|
|
|
{
|
|
|
|
char buf[BUF_SIZE];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < count; ++i)
|
|
|
|
read(fd, buf, BUF_SIZE);
|
|
|
|
}
|
|
|
|
|
2018-05-08 01:50:49 +08:00
|
|
|
int main(int argc, char *argv[])
|
2018-03-15 01:23:22 +08:00
|
|
|
{
|
|
|
|
int fd = open("/dev/urandom", O_RDONLY);
|
2018-05-08 01:50:49 +08:00
|
|
|
int count = 4;
|
2018-03-15 01:23:22 +08:00
|
|
|
|
|
|
|
if (fd < 0)
|
|
|
|
return 1;
|
2018-05-08 01:50:49 +08:00
|
|
|
|
|
|
|
if (argc == 2)
|
|
|
|
count = atoi(argv[1]);
|
|
|
|
|
2019-03-16 04:04:14 +08:00
|
|
|
urandom_read(fd, count);
|
2018-03-15 01:23:22 +08:00
|
|
|
|
|
|
|
close(fd);
|
|
|
|
return 0;
|
|
|
|
}
|