-
Notifications
You must be signed in to change notification settings - Fork 0
/
tferand.c
42 lines (36 loc) · 823 Bytes
/
tferand.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include "tfdef.h"
#include "tfe.h"
#include "tfsupport.h"
static char data[DATASIZE];
static char key[TF_KEY_SIZE];
static tf_fsize howmuch = NOFSIZE, generated;
static struct tfe_stream tfe;
int main(int argc, char **argv)
{
int fd;
char *stoi;
size_t x;
fd = open("/dev/urandom", O_RDONLY);
if (fd != -1) {
read(fd, key, sizeof(key));
close(fd);
}
if (argc >= 2) {
howmuch = tf_humanfsize(argv[1], &stoi);
if (*stoi) howmuch = NOFSIZE;
}
tfe_init(&tfe, key);
while (1) {
x = blk_len_adjust(howmuch, generated, sizeof(data));
tfe_emit(data, x, &tfe);
if (write(1, data, x) == -1) return 1;
generated += x;
if (howmuch != NOFSIZE && generated >= howmuch) break;
}
tfe_emit(NULL, 0, &tfe);
return 0;
}