Unverified Commit 6c6bb8ad authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

feh_http_load_image: Use mkstemps to save image with correct suffix

This allows feh to load .gif images via libcurl, as some imlib2 versions only
load gif images if the suffix is correct. It's also more convenient when using
--keep-http.

To achieve this, feh needs to use mkstemps. mkstemps is a non-standard
extension that is available on several systems. Compile feh with
"mkstemps=0" to use mkstemp instead.

Closes #630
parent 707892f2
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -91,6 +91,7 @@ indicates that the corresponding feature is enabled by default.
| help | 0 | include help text (refers to the manpage otherwise) |
| inotify | 0 | enable inotify, needed for `--auto-reload` |
| stat64 | 0 | Support CIFS shares from 64bit hosts on 32bit machines |
| mkstemps | 1 | Whether your libc provides `mkstemps()`. If set to 0, feh will be unable to load gif images via libcurl |
| verscmp | 1 | Whether your libc provides `strvercmp()`. If set to 0, feh will use an internal implementation. |
| xinerama | 1 | Support Xinerama/XRandR multiscreen setups |

+5 −0
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ curl ?= 1
debug ?= 0
exif ?= 0
help ?= 0
mkstemps ?= 1
verscmp ?= 1
xinerama ?= 1

@@ -63,6 +64,10 @@ ifeq (${stat64},1)
	CFLAGS += -D_FILE_OFFSET_BITS=64
endif

ifeq (${mkstemps},1)
	CFLAGS += -DHAVE_MKSTEMPS
endif

ifeq (${verscmp},1)
	CFLAGS += -DHAVE_STRVERSCMP
endif
+25 −4
Original line number Diff line number Diff line
@@ -869,15 +869,32 @@ static char *feh_http_load_image(char *url)
	}

	basename = strrchr(url, '/') + 1;
	tmpname = feh_unique_filename(path, basename);

	if (strlen(tmpname) > (NAME_MAX-6))
		tmpname[NAME_MAX-7] = '\0';
#ifdef HAVE_MKSTEMPS
	tmpname = estrjoin("_", "feh_curl_XXXXXX", basename, NULL);

	sfn = estrjoin("_", tmpname, "XXXXXX", NULL);
	if (strlen(tmpname) > NAME_MAX) {
		tmpname[NAME_MAX] = '\0';
	}
#else
	if (strlen(basename) > NAME_MAX-7) {
		tmpname = estrdup("feh_curl_XXXXXX");
	} else {
		tmpname = estrjoin("_", "feh_curl", basename, "XXXXXX", NULL);
	}
#endif

	sfn = estrjoin("", path, tmpname, NULL);
	free(tmpname);

	D(("sfn is %s\n", sfn))

#ifdef HAVE_MKSTEMPS
	fd = mkstemps(sfn, strlen(basename) + 1);
#else
	fd = mkstemp(sfn);
#endif

	if (fd != -1) {
		sfp = fdopen(fd, "w+");
		if (sfp != NULL) {
@@ -936,7 +953,11 @@ static char *feh_http_load_image(char *url)
			close(fd);
		}
	} else {
#ifdef HAVE_MKSTEMPS
		weprintf("open url: mkstemps failed:");
#else
		weprintf("open url: mkstemp failed:");
#endif
		free(sfn);
	}
	curl_easy_cleanup(curl);