From ab0db69a7b11ba1a9dc52d50c94e9e321b70ebf0 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Fri, 6 Jun 2025 09:13:54 +0200 Subject: Added example 6 --- 06_storage/storage.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 06_storage/storage.c (limited to '06_storage/storage.c') 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 @@ +#include +#include + +#include "primes.h" + +#define FILENAME "/assets/primes_table" + +bool read_table(unsigned char *table) { + FILE *f = fopen(FILENAME, "rb"); + if (f == NULL) + return false; + + int b = fread(table, TABLESIZE, 1, f); + fclose(f); + + return b == 1; +} + +bool store_table(const unsigned char *table) { + FILE *f = fopen(FILENAME, "wb"); + if (f == NULL) + return false; + + int b = fwrite(table, TABLESIZE, 1, f); + fclose(f); + + return b == 1; +} -- cgit v1.3