Give savefiles an identifting header. SAve format version gets bumped.
authorEric S. Raymond <esr@thyrsus.com>
Thu, 6 Apr 2023 21:54:02 +0000 (17:54 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Thu, 6 Apr 2023 21:54:02 +0000 (17:54 -0400)
advent.h
saveresume.c
tests/resumefail2.chk

index faf298e04af52eee8aed786dbfcecd0b56c235b1..f9a6a9ae84f555e335bbf0ffb36f42d8e4a59ca1 100644 (file)
--- a/advent.h
+++ b/advent.h
@@ -233,7 +233,12 @@ typedef struct {
  * files afterwards.  Otherwise you will get a spurious failure due to the old version
  * having been generated into a check file.
  */
  * files afterwards.  Otherwise you will get a spurious failure due to the old version
  * having been generated into a check file.
  */
-#define SAVE_VERSION   29
+#define SAVE_VERSION   30
+
+/*
+ * Goes at start of gile so sabes can be identified by file(1) and the like.
+ */
+#define ADVENT_MAGIC   "open-adventure\n"
 
 /*
  * If you change the first three members, the resume function may not properly
 
 /*
  * If you change the first three members, the resume function may not properly
@@ -241,8 +246,7 @@ typedef struct {
  * when you do that.
  */
 struct save_t {
  * when you do that.
  */
 struct save_t {
-    int64_t savetime;
-    int32_t mode;              /* not used, must be present for version detection */
+    char magic[sizeof(ADVENT_MAGIC)];
     int32_t version;
     struct game_t game;
 };
     int32_t version;
     struct game_t game;
 };
index 858498235fae8d5835e4638edf02f334911ec596..76de1c4300b5ec633a342781a61f09f5bcfbc2d0 100644 (file)
@@ -25,8 +25,7 @@ struct save_t save;
 int savefile(FILE *fp, int32_t version)
 /* Save game to file. No input or output from user. */
 {
 int savefile(FILE *fp, int32_t version)
 /* Save game to file. No input or output from user. */
 {
-    save.savetime = time(NULL);
-    save.mode = -1;
+    memcpy(&save.magic, ADVENT_MAGIC, sizeof(ADVENT_MAGIC));
     save.version = (version == 0) ? SAVE_VERSION : version;
 
     save.game = game;
     save.version = (version == 0) ? SAVE_VERSION : version;
 
     save.game = game;
index 931c72dd4ac710de19f3846bb409059b86e75a71..7493ad8232fdf9fe59eaa04b9cf65a7e2241a203 100644 (file)
@@ -11,7 +11,7 @@ down a gully.
 Can't open file y, try again.
 
 I'm sorry, but that Adventure was begun using Version -133.-7 of the
 Can't open file y, try again.
 
 I'm sorry, but that Adventure was begun using Version -133.-7 of the
-save file format, and this program uses Version 2.9.  You must find an instance
+save file format, and this program uses Version 3.0.  You must find an instance
 using that other version in order to resume that Adventure.
 
 You're in front of building.
 using that other version in order to resume that Adventure.
 
 You're in front of building.