diff options
Diffstat (limited to 'crypto.c')
-rw-r--r-- | crypto.c | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -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 |