aboutsummaryrefslogtreecommitdiff
path: root/06_storage/storage.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--06_storage/storage.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/06_storage/storage.c b/06_storage/storage.c
new file mode 100644
index 0000000..7542022
--- /dev/null
+++ b/06_storage/storage.c
@@ -0,0 +1,28 @@
1#include <stdio.h>
2#include <stdbool.h>
3
4#include "primes.h"
5
6#define FILENAME "/assets/primes_table"
7
8bool read_table(unsigned char *table) {
9 FILE *f = fopen(FILENAME, "rb");
10 if (f == NULL)
11 return false;
12
13 int b = fread(table, TABLESIZE, 1, f);
14 fclose(f);
15
16 return b == 1;
17}
18
19bool store_table(const unsigned char *table) {
20 FILE *f = fopen(FILENAME, "wb");
21 if (f == NULL)
22 return false;
23
24 int b = fwrite(table, TABLESIZE, 1, f);
25 fclose(f);
26
27 return b == 1;
28}

Generated with cgit - Back to sebastiano.tronto.net