From 13f16feb81a8fd2510a406138971bd9a5db192b0 Mon Sep 17 00:00:00 2001
From: Daniel Friesel <derf@finalrewind.org>
Date: Tue, 7 Apr 2015 12:21:01 +0200
Subject: [PATCH] fix gib_imlib_save_image_with_error_return in imported giblib
 code

---
 src/feh.h       |  2 --
 src/gib_imlib.c | 23 ++++++++++++++++-------
 src/imlib.c     | 28 +---------------------------
 src/index.c     |  2 +-
 src/slideshow.c |  2 +-
 src/thumbnail.c |  2 +-
 6 files changed, 20 insertions(+), 39 deletions(-)

diff --git a/src/feh.h b/src/feh.h
index a4c01f5..a2a586a 100644
--- a/src/feh.h
+++ b/src/feh.h
@@ -162,8 +162,6 @@ void feh_reload_image(winwidget w, int resize, int force_new);
 void feh_filelist_image_remove(winwidget winwid, char do_delete);
 void feh_imlib_print_load_error(char *file, winwidget w, Imlib_Load_Error err);
 void slideshow_save_image(winwidget win);
-void ungib_imlib_save_image_with_error_return(Imlib_Image im, char *file,
-	Imlib_Load_Error * error_return);
 void feh_edit_inplace(winwidget w, int orientation);
 void feh_edit_inplace_lossless(winwidget w, int orientation);
 gib_list *feh_wrap_string(char *text, int wrap_width, Imlib_Font fn, gib_style * style);
diff --git a/src/gib_imlib.c b/src/gib_imlib.c
index b53b1cc..8f401aa 100644
--- a/src/gib_imlib.c
+++ b/src/gib_imlib.c
@@ -527,13 +527,22 @@ void
 gib_imlib_save_image_with_error_return(Imlib_Image im, char *file,
                                        Imlib_Load_Error * error_return)
 {
-   char *tmp;
-
-   imlib_context_set_image(im);
-   tmp = strrchr(file, '.');
-   if (tmp)
-      imlib_image_set_format(tmp + 1);
-   imlib_save_image_with_error_return(file, error_return);
+    char *tmp;
+
+    imlib_context_set_image(im);
+    tmp = strrchr(file, '.');
+    if (tmp) {
+        char *p, *pp;
+        p = estrdup(tmp + 1);
+        pp = p;
+        while(*pp) {
+            *pp = tolower(*pp);
+            pp++;
+        }
+        imlib_image_set_format(p);
+        free(p);
+    }
+    imlib_save_image_with_error_return(file, error_return);
 }
 
 void
diff --git a/src/imlib.c b/src/imlib.c
index b3bf04b..10ab718 100644
--- a/src/imlib.c
+++ b/src/imlib.c
@@ -148,32 +148,6 @@ int feh_load_image_char(Imlib_Image * im, char *filename)
 	return(i);
 }
 
-/*
- * XXX gib_imlib_save_image_with_error_return breaks with *.END and
- * similar because it tries to set the image format, which only works
- * with .end .
- * So we leave that part out.
- */
-void ungib_imlib_save_image_with_error_return(Imlib_Image im, char *file,
-	Imlib_Load_Error * error_return)
-{
-	char *tmp;
-	imlib_context_set_image(im);
-	tmp = strrchr(file, '.');
-	if (tmp) {
-		char *p, *pp;
-		p = estrdup(tmp + 1);
-		pp = p;
-		while(*pp) {
-			*pp = tolower(*pp);
-			pp++;
-		}
-		imlib_image_set_format(p);
-		free(p);
-	}
-	imlib_save_image_with_error_return(file, error_return);
-}
-
 void feh_imlib_print_load_error(char *file, winwidget w, Imlib_Load_Error err)
 {
 	if (err == IMLIB_LOAD_ERROR_OUT_OF_FILE_DESCRIPTORS)
@@ -1055,7 +1029,7 @@ void feh_edit_inplace(winwidget w, int op)
 			imlib_image_flip_horizontal();
 		} else
 			gib_imlib_image_orientate(old, op);
-		ungib_imlib_save_image_with_error_return(old,
+		gib_imlib_save_image_with_error_return(old,
 			FEH_FILE(w->file->data)->filename, &err);
 		gib_imlib_free_image(old);
 		if (err)
diff --git a/src/index.c b/src/index.c
index db2c9d2..a71744d 100644
--- a/src/index.c
+++ b/src/index.c
@@ -327,7 +327,7 @@ void init_index_mode(void)
 		else
 			strncpy(output_buf, opt.output_file, 1024);
 
-		ungib_imlib_save_image_with_error_return(im_main, output_buf, &err);
+		gib_imlib_save_image_with_error_return(im_main, output_buf, &err);
 		if (err) {
 			feh_imlib_print_load_error(output_buf, im_main, err);
 		}
diff --git a/src/slideshow.c b/src/slideshow.c
index 08db2cb..e42bd23 100644
--- a/src/slideshow.c
+++ b/src/slideshow.c
@@ -664,7 +664,7 @@ void slideshow_save_image(winwidget win)
 	if (opt.verbose)
 		fprintf(stderr, "saving image to filename '%s'\n", tmpname);
 
-	ungib_imlib_save_image_with_error_return(win->im, tmpname, &err);
+	gib_imlib_save_image_with_error_return(win->im, tmpname, &err);
 
 	if (err)
 		feh_imlib_print_load_error(tmpname, win, err);
diff --git a/src/thumbnail.c b/src/thumbnail.c
index 1719fdc..c806ce4 100644
--- a/src/thumbnail.c
+++ b/src/thumbnail.c
@@ -382,7 +382,7 @@ void init_thumbnail_mode(void)
 			snprintf(output_buf, 1024, "%s/%s", opt.output_dir, opt.output_file);
 		else
 			strncpy(output_buf, opt.output_file, 1024);
-		ungib_imlib_save_image_with_error_return(td.im_main, output_buf, &err);
+		gib_imlib_save_image_with_error_return(td.im_main, output_buf, &err);
 		if (err) {
 			feh_imlib_print_load_error(output_buf, td.im_main, err);
 		}
-- 
GitLab