From 488716ef22ac5a1aae235a59bea2997ac7e8e45a Mon Sep 17 00:00:00 2001 From: Andrey Rys Date: Thu, 16 May 2019 19:43:03 +0200 Subject: [PATCH] tfrand: first cmdline argument defines random source file name. --- tfrand.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/tfrand.c b/tfrand.c index 5372e20..bd26f35 100644 --- a/tfrand.c +++ b/tfrand.c @@ -1,3 +1,5 @@ +#include +#include #include #include #include @@ -13,11 +15,25 @@ static char key[TFNG_KEY_SIZE]; int main(int argc, char **argv) { int fd; + char *randsource; - fd = open("/dev/urandom", O_RDONLY); + if (argc > 1 && argv[1]) { + if (!strcmp(argv[1], "-")) { + fd = 0; + goto _stdinrnd; + } + randsource = argv[1]; + } + else randsource = "/dev/urandom"; + + fd = open(randsource, O_RDONLY); if (fd != -1) { - read(fd, key, sizeof(key)); - close(fd); +_stdinrnd: read(fd, key, sizeof(key)); + if (fd != 0) close(fd); + } + else { + perror(argv[1]); + return 1; } tfng_prng_seedkey(key);