summaryrefslogtreecommitdiff
path: root/src/test/ao_lisp_test.c
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2016-11-11 21:18:50 -0800
committerKeith Packard <keithp@keithp.com>2017-02-20 11:16:50 -0800
commit8f2d60b4c029bffaa559bd1f31f5b15230dfa674 (patch)
tree3b19d160542e3bcf26625f023f572658e8f79127 /src/test/ao_lisp_test.c
parentdba374516ed396633659dec571b6a44b03da8ad1 (diff)
altos/lisp: Add save/restore to ao_lisp_test
Allow testing of the save/restore code under Linux. Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/test/ao_lisp_test.c')
-rw-r--r--src/test/ao_lisp_test.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/test/ao_lisp_test.c b/src/test/ao_lisp_test.c
index 69739100..41dae07a 100644
--- a/src/test/ao_lisp_test.c
+++ b/src/test/ao_lisp_test.c
@@ -18,6 +18,39 @@
static FILE *ao_lisp_file;
static int newline = 1;
+static char save_file[] = "lisp.image";
+
+int
+ao_lisp_os_save(void)
+{
+ FILE *save = fopen(save_file, "w");
+
+ if (!save) {
+ perror(save_file);
+ return 0;
+ }
+ fwrite(ao_lisp_pool, 1, AO_LISP_POOL_TOTAL, save);
+ fclose(save);
+ return 1;
+}
+
+int
+ao_lisp_os_restore(void)
+{
+ FILE *restore = fopen(save_file, "r");
+ size_t ret;
+
+ if (!restore) {
+ perror(save_file);
+ return 0;
+ }
+ ret = fread(ao_lisp_pool, 1, AO_LISP_POOL_TOTAL, restore);
+ fclose(restore);
+ if (ret != AO_LISP_POOL_TOTAL)
+ return 0;
+ return 1;
+}
+
int
ao_lisp_getc(void)
{