summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/feh_png.c6
-rw-r--r--src/feh_png.h2
-rw-r--r--src/thumbnail.c16
3 files changed, 18 insertions, 6 deletions
diff --git a/src/feh_png.c b/src/feh_png.c
index 129eb45..ff73f56 100644
--- a/src/feh_png.c
+++ b/src/feh_png.c
@@ -94,7 +94,7 @@ gib_hash *feh_png_read_comments(char *file)
}
/* grab image data from image and write info file with comments ... */
-int feh_png_write_png(Imlib_Image image, char *file, ...)
+int feh_png_write_png_fd(Imlib_Image image, int fd, ...)
{
FILE *fp;
int i, w, h;
@@ -111,7 +111,7 @@ int feh_png_write_png(Imlib_Image image, char *file, ...)
char *pair_key, *pair_text;
#endif /* PNG_TEXT_SUPPORTED */
- if (!(fp = fopen(file, "wb")))
+ if (!(fp = fdopen(fd, "wb")))
return 0;
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
@@ -155,7 +155,7 @@ int feh_png_write_png(Imlib_Image image, char *file, ...)
png_set_sBIT(png_ptr, info_ptr, &sig_bit);
#ifdef PNG_TEXT_SUPPORTED
- va_start(args, file);
+ va_start(args, fd);
for (i = 0; i < FEH_PNG_NUM_COMMENTS; i++) {
if ((pair_key = va_arg(args, char *))
&& (pair_text = va_arg(args, char *))) {
diff --git a/src/feh_png.h b/src/feh_png.h
index 6502978..ac3375f 100644
--- a/src/feh_png.h
+++ b/src/feh_png.h
@@ -32,7 +32,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <stdarg.h>
gib_hash *feh_png_read_comments(char *file);
-int feh_png_write_png(Imlib_Image image, char *file, ...);
+int feh_png_write_png_fd(Imlib_Image image, int fd, ...);
int feh_png_file_is_png(FILE * fp);
diff --git a/src/thumbnail.c b/src/thumbnail.c
index 462b478..9bb1862 100644
--- a/src/thumbnail.c
+++ b/src/thumbnail.c
@@ -673,6 +673,8 @@ int feh_thumbnail_generate(Imlib_Image * image, feh_file * file,
Imlib_Image im_temp;
struct stat sb;
char c_width[8], c_height[8];
+ char *tmp_thumb_file, *prefix;
+ int tmp_fd;
if (feh_load_image(&im_temp, file) != 0) {
*orig_w = w = gib_imlib_image_get_width(im_temp);
@@ -696,10 +698,20 @@ int feh_thumbnail_generate(Imlib_Image * image, feh_file * file,
sprintf(c_mtime, "%d", (int)sb.st_mtime);
snprintf(c_width, 8, "%d", w);
snprintf(c_height, 8, "%d", h);
- feh_png_write_png(*image, thumb_file, "Thumb::URI", uri,
+ prefix = feh_thumbnail_get_prefix();
+ tmp_thumb_file = estrjoin("/", prefix, ".feh_thumbnail_XXXXXX", NULL);
+ free(prefix);
+ tmp_fd = mkstemp(tmp_thumb_file);
+ if (!feh_png_write_png_fd(*image, tmp_fd, "Thumb::URI", uri,
"Thumb::MTime", c_mtime,
"Thumb::Image::Width", c_width,
- "Thumb::Image::Height", c_height);
+ "Thumb::Image::Height", c_height)) {
+ rename(tmp_thumb_file, thumb_file);
+ } else {
+ unlink(tmp_thumb_file);
+ }
+ close(tmp_fd);
+ free(tmp_thumb_file);
}
gib_imlib_free_image_and_decache(im_temp);