storage.c (468B)
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 }