use a c program to fill the file

it's several order of magnitude faster than the equivalent shell script
This commit is contained in:
Omar Polo 2021-01-22 17:18:55 +00:00
parent 99f95f7762
commit 609fc9f9d9
3 changed files with 37 additions and 2 deletions

3
.gitignore vendored
View File

@ -16,3 +16,6 @@ configure.local
regress/testdata
regress/*.pem
regress/reg.conf
regress/fill-file
regress/iri_test
regress/*.o

View File

@ -8,6 +8,9 @@ all: iri_test runtime
iri_test: iri_test.o ../iri.o ../utf8.o
${CC} iri_test.o ../iri.o ../utf8.o -o iri_test ${LDFLAGS}
fill-file: fill-file.o
${CC} fill-file.o -o fill-file
key.pem: cert.pem
# XXX: key size is NOT GOOD. This is only for testing. Smaller keys
@ -24,9 +27,9 @@ clean:
rm -f *.o iri_test cert.pem key.pem
rm -rf testdata
testdata:
testdata: fill-file
mkdir testdata
./genbigfile testdata/bigfile
./fill-file testdata/bigfile
./sha testdata/bigfile testdata/bigfile.sha
printf "# hello world\n" > testdata/index.gmi
./sha testdata/index.gmi testdata/index.gmi.sha

29
regress/fill-file.c Normal file
View File

@ -0,0 +1,29 @@
#include <stdio.h>
/* I need a big file made up of ascii characters. dd if=/dev/zero is
* thus not an option, truncate is not portable. This is some order
* of magnitude faster than the equivalent sh script */
int
main(int argc, char **argv)
{
FILE *out;
int i, j;
if (argc != 2) {
fprintf(stderr, "USAGE: %s <file>\n", *argv);
return 1;
}
if ((out = fopen(argv[1], "w")) == NULL) {
fprintf(stderr, "cannot open file: %s\n", argv[1]);
return 1;
}
for (i = 0; i < 1024; ++i)
for (j = 0; j < 1024; ++j)
fprintf(out, "a\n");
fclose(out);
return 0;
}