From a974cdd6664ac23668baf50cdafe80b8c8838b1c Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Wed, 14 Aug 2013 11:35:12 +0200 Subject: [PATCH] Move checking for error results into exit_err(), out of conditionals in the remaining code. --- src/rexit.c | 6 +++++- src/rexit.h | 12 +++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/rexit.c b/src/rexit.c index f7bb3f2..223c79b 100644 --- a/src/rexit.c +++ b/src/rexit.c @@ -59,8 +59,12 @@ extern void exit_game(struct World * world) -extern void exit_err(struct World * world, char * msg) +extern void exit_err(unsigned char fail, struct World * world, char * msg) { + if (0 == fail) + { + return; + } cleanup(world); printf(msg); exit(EXIT_FAILURE); diff --git a/src/rexit.h b/src/rexit.h index 8a5444f..d4b19d7 100644 --- a/src/rexit.h +++ b/src/rexit.h @@ -29,10 +29,16 @@ extern void set_cleanup_flag(enum cleanup_flag flag); -/* Exit orderly without message or on error with an error message ("msg"). - */ +/* Exit orderly, clean up. */ extern void exit_game(struct World * world); -extern void exit_err(struct World * world, char * msg); + + + +/* If fail != 0, exit with an error message "msg" and clean up. (For "fail", + * pass the result of functions that return non-zero as an error status and + * thereby avoid bloating up the code with if-error-conditionals.) + */ +extern void exit_err(unsigned char fail, struct World * world, char * msg); -- 2.30.2