diff options
Diffstat (limited to '06_storage/storage.c')
| -rw-r--r-- | 06_storage/storage.c | 28 |
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 | |||
| 8 | bool 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 | |||
| 19 | bool 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 | } | ||
