aboutsummaryrefslogtreecommitdiff
path: root/crypto.c
diff options
context:
space:
mode:
authorFranklin Wei <me@fwei.tk>2018-07-18 23:37:45 -0400
committerFranklin Wei <me@fwei.tk>2018-07-18 23:37:45 -0400
commit75e5bf09506412ac679d60dc051f97d99d24702d (patch)
tree67de107d7a39ffee14aaec877eb245eca44e3c07 /crypto.c
parentdc5df5430888f2ff4054d87086f0f8d3689af644 (diff)
downloadcsaa-75e5bf09506412ac679d60dc051f97d99d24702d.zip
csaa-75e5bf09506412ac679d60dc051f97d99d24702d.tar.gz
csaa-75e5bf09506412ac679d60dc051f97d99d24702d.tar.bz2
csaa-75e5bf09506412ac679d60dc051f97d99d24702d.tar.xz
Add a compile-time option to do database prepopulation and exit
Enabling the PREPOPULATE macro in service_provider.c will cause it to initialize a database with 2^logleaves - RUNS_TEST files, and exit. This allows fast testing on the resulting database at near full load.
Diffstat (limited to 'crypto.c')
-rw-r--r--crypto.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/crypto.c b/crypto.c
index 0bef799..5d10101 100644
--- a/crypto.c
+++ b/crypto.c
@@ -500,6 +500,30 @@ void serialize_file(int cl, const void *buf, size_t len)
write(cl, buf, len);
}
+void *load_file(const char *path, size_t *len)
+{
+ if(!path)
+ return NULL;
+
+ FILE *f = fopen(path, "r");
+ fseek(f, 0, SEEK_END);
+ *len = ftell(f);
+ fseek(f, 0, SEEK_SET);
+ void *buf = malloc(*len);
+ fread(buf, 1, *len, f);
+ return buf;
+}
+
+void write_file(const char *path, const void *contents, size_t len)
+{
+ if(contents)
+ {
+ FILE *f = fopen(path, "w");
+ fwrite(contents, 1, len, f);
+ fclose(f);
+ }
+}
+
void crypto_test(void)
{
#if 1