From d3a70a285d03224fde9e6ef36eba9de21b773f39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bert=20M=C3=BCnnich?= Date: Wed, 28 Oct 2015 23:03:37 +0100 Subject: Revised error handling - Functions warn() and die() replaced by GNU-like error(3) function - Register cleanup() with atexit(3) - Functions called by cleanup() are marked with CLEANUP and are not allowed to call exit(3) --- image.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'image.c') diff --git a/image.c b/image.c index 494ff07..e067c71 100644 --- a/image.c +++ b/image.c @@ -16,6 +16,7 @@ * along with sxiv. If not, see . */ +#include #include #include #include @@ -149,7 +150,7 @@ bool img_load_gif(img_t *img, const fileinfo_t *file) gif = DGifOpenFileName(file->path); #endif if (gif == NULL) { - warn("could not open gif file: %s", file->name); + error(0, 0, "%s: Error opening gif image", file->name); return false; } bg = gif->SBackGroundColor; @@ -274,7 +275,7 @@ bool img_load_gif(img_t *img, const fileinfo_t *file) #endif if (err && (file->flags & FF_WARN)) - warn("corrupted gif file: %s", file->name); + error(0, 0, "%s: Corrupted gif file", file->name); if (img->multi.cnt > 1) { imlib_context_set_image(img->im); @@ -300,7 +301,7 @@ bool img_load(img_t *img, const fileinfo_t *file) (img->im = imlib_load_image(file->path)) == NULL) { if (file->flags & FF_WARN) - warn("could not open image: %s", file->name); + error(0, 0, "%s: Error opening image", file->name); return false; } @@ -325,7 +326,7 @@ bool img_load(img_t *img, const fileinfo_t *file) return true; } -void img_close(img_t *img, bool decache) +CLEANUP void img_close(img_t *img, bool decache) { int i; @@ -464,7 +465,7 @@ void img_render(img_t *img) if (imlib_image_has_alpha()) { if ((bg = imlib_create_image(dw, dh)) == NULL) - die("could not allocate memory"); + error(EXIT_FAILURE, ENOMEM, NULL); imlib_context_set_image(bg); imlib_image_set_has_alpha(0); -- cgit v1.2.3