From d16822a5837f5243e708b5349dbb0e4144152a23 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Thu, 6 Apr 2023 17:54:02 -0400 Subject: [PATCH] Give savefiles an identifting header. SAve format version gets bumped. --- advent.h | 10 +++++++--- saveresume.c | 3 +-- tests/resumefail2.chk | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/advent.h b/advent.h index faf298e..f9a6a9a 100644 --- 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. */ -#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 @@ -241,8 +246,7 @@ typedef struct { * 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; }; diff --git a/saveresume.c b/saveresume.c index 8584982..76de1c4 100644 --- a/saveresume.c +++ b/saveresume.c @@ -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. */ { - 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; diff --git a/tests/resumefail2.chk b/tests/resumefail2.chk index 931c72d..7493ad8 100644 --- a/tests/resumefail2.chk +++ b/tests/resumefail2.chk @@ -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 -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. -- 2.31.1