interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / helper / test-csprng.c

28 lines · 562 bytes Raw Blame History
1#include "test-tool.h"
2#include "git-compat-util.h"
3
4int cmd__csprng(int argc, const char **argv)
5{
6 unsigned long count;
7 unsigned char buf[1024];
8
9 if (argc > 2) {
10 fprintf(stderr, "usage: %s [<size>]\n", argv[0]);
11 return 2;
12 }
13
14 count = (argc == 2) ? strtoul(argv[1], NULL, 0) : ULONG_MAX;
15
16 while (count) {
17 unsigned long chunk = count < sizeof(buf) ? count : sizeof(buf);
18 if (csprng_bytes(buf, chunk, 0) < 0) {
19 perror("failed to read");
20 return 5;
21 }
22 if (fwrite(buf, chunk, 1, stdout) != chunk)
23 return 1;
24 count -= chunk;
25 }
26
27 return 0;
28}