commit acea668e78da1ca217c2a7ebd16f4995c4796fb4
parent f0287aa05e7c01f71baa3eb2c4a0dff9e283b8d0
Author: Frederic Cambus <fred@statdns.com>
Date: Wed, 20 May 2020 20:12:53 +0200
Refactor error handling in ansilove_savefile().
Diffstat:
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/src/savefile.c b/src/savefile.c
@@ -25,13 +25,15 @@ ansilove_savefile(struct ansilove_ctx *ctx, char *output)
FILE *file = fopen(output, "wb");
- if (file) {
- fwrite(ctx->png.buffer, ctx->png.length, 1, file);
- fclose(file);
- } else {
- ctx->error = ANSILOVE_FILE_WRITE_ERROR;
- return -1;
- }
+ if (!file)
+ goto err;
+
+ fwrite(ctx->png.buffer, ctx->png.length, 1, file);
+ fclose(file);
return 0;
+
+err:
+ ctx->error = ANSILOVE_FILE_WRITE_ERROR;
+ return -1;
}