aboutsummaryrefslogtreecommitdiff
path: root/06_storage/storage.c
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-06-06 09:13:54 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2025-06-06 09:13:54 +0200
commitab0db69a7b11ba1a9dc52d50c94e9e321b70ebf0 (patch)
tree76be6a8b1596ea1e74dbf7085b85214c2c83e69a /06_storage/storage.c
parent961c3470d7e9bdf5efbe0509f586be75d7052d8b (diff)
downloademscripten-tutorial-ab0db69a7b11ba1a9dc52d50c94e9e321b70ebf0.tar.gz
emscripten-tutorial-ab0db69a7b11ba1a9dc52d50c94e9e321b70ebf0.zip
Added example 6
Diffstat (limited to '06_storage/storage.c')
-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