home · contact · privacy
save_game() now checks for the error return code of opening the savefile.
authorChristian Heller <c.heller@plomlompom.de>
Wed, 21 Aug 2013 02:50:07 +0000 (04:50 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 21 Aug 2013 02:50:07 +0000 (04:50 +0200)
src/misc.c

index cfa43caf14b7054e682d631a20b85e328a1bfbd9..883325289475b850a3814c213262a262806bb645 100644 (file)
@@ -133,8 +133,13 @@ extern void turn_over(struct World * world, char action)
 
 extern void save_game(struct World * world)
 {
-    uint8_t err;
+    uint8_t err = 0;
+    char * err_msg = "Error saving game.";
+
     FILE * file = fopen("savefile", "w");
+    // err = (0 == file);
+    exit_err(0 == file, world, err_msg);
+
     err = write_uint32_bigendian(world->seed, file);
     err = err | write_uint32_bigendian(world->turn, file);
     err = err | write_uint16_bigendian(world->player->pos.y + 1, file);
@@ -142,7 +147,7 @@ extern void save_game(struct World * world)
     err = err | write_uint8(world->player->hitpoints, file);
     err = err | write_map_objects(world, world->monster, file);
     err = err | write_map_objects(world, world->item, file);
-    exit_err(err, world, "Error saving game.");
+    exit_err(err, world, err_msg);
     fclose(file);
 }