Files
git/t/helper/test-csprng.c
Patrick Steinhardt 41f43b8243 global: mark code units that generate warnings with -Wsign-compare
Mark code units that generate warnings with `-Wsign-compare`. This
allows for a structured approach to get rid of all such warnings over
time in a way that can be easily measured.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-12-06 20:20:02 +09:00

32 lines
593 B
C

#define DISABLE_SIGN_COMPARE_WARNINGS
#include "test-tool.h"
#include "git-compat-util.h"
int cmd__csprng(int argc, const char **argv)
{
unsigned long count;
unsigned char buf[1024];
if (argc > 2) {
fprintf(stderr, "usage: %s [<size>]\n", argv[0]);
return 2;
}
count = (argc == 2) ? strtoul(argv[1], NULL, 0) : -1L;
while (count) {
unsigned long chunk = count < sizeof(buf) ? count : sizeof(buf);
if (csprng_bytes(buf, chunk) < 0) {
perror("failed to read");
return 5;
}
if (fwrite(buf, chunk, 1, stdout) != chunk)
return 1;
count -= chunk;
}
return 0;
}