aboutsummaryrefslogtreecommitdiff
path: root/crypto.c
diff options
context:
space:
mode:
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