diff options
| author | Daniel Friesel <derf@finalrewind.org> | 2021-09-09 21:14:35 +0200 | 
|---|---|---|
| committer | Daniel Friesel <derf@finalrewind.org> | 2021-09-09 21:14:35 +0200 | 
| commit | 6c6bb8adaaf3c4e20b5a1e5dbdc02e25b0a00e85 (patch) | |
| tree | 5bf1b8a99eff573acdea55db7f29d1ef59f51b7b /src | |
| parent | 707892f24b6b6133f9bffc0b02ae300fbe3f6ad5 (diff) | |
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
Diffstat (limited to 'src')
| -rw-r--r-- | src/imlib.c | 29 | 
1 files changed, 25 insertions, 4 deletions
| diff --git a/src/imlib.c b/src/imlib.c index ea2f49c..add88d6 100644 --- a/src/imlib.c +++ b/src/imlib.c @@ -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); | 
