diff options
author | Руслан Ижбулатов <lrn1986@gmail.com> | 2017-10-01 02:50:54 +0000 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2017-11-29 20:11:05 +0100 |
commit | ce52cefbbc7c6910cd6fd99c7321292b91202009 (patch) | |
tree | 428973a6378f21a57eb7f60726b0546f1ea9f6d9 | |
parent | 204082e6a7a404ec7372d78ef7a7890ada595154 (diff) | |
download | gdk-pixbuf-ce52cefbbc7c6910cd6fd99c7321292b91202009.tar.gz |
io-tiff: Correctly work with WIN32-IO version of libtiff
If libtiff is compiled with WIN32-IO (which is the default,
unless it's built for Cygwin), it works with HANDLEs, not
C runtime FDs.
https://bugzilla.gnome.org/show_bug.cgi?id=788388
-rw-r--r-- | gdk-pixbuf/io-tiff.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/gdk-pixbuf/io-tiff.c b/gdk-pixbuf/io-tiff.c index 7d055cfa8..7ca0a565a 100644 --- a/gdk-pixbuf/io-tiff.c +++ b/gdk-pixbuf/io-tiff.c @@ -41,6 +41,7 @@ #ifdef G_OS_WIN32 #include <fcntl.h> #include <io.h> +#include <Windows.h> #define lseek(a,b,c) _lseek(a,b,c) #define O_RDWR _O_RDWR #endif @@ -315,7 +316,7 @@ tiff_image_parse (TIFF *tiff, TiffContext *context, GError **error) static GdkPixbuf * gdk_pixbuf__tiff_image_load (FILE *f, GError **error) { - TIFF *tiff; + TIFF *tiff = NULL; int fd; GdkPixbuf *pixbuf; @@ -331,7 +332,30 @@ gdk_pixbuf__tiff_image_load (FILE *f, GError **error) * before using it. (#60840) */ lseek (fd, 0, SEEK_SET); +#ifndef G_OS_WIN32 tiff = TIFFFdOpen (fd, "libpixbuf-tiff", "r"); +#else + /* W32 version of this function takes HANDLE. + * What's worse, the caller will close the file, + * but TIFFClose() will *also* close it, so we + * need to make a duplicate. + */ + { + HANDLE h; + + if (DuplicateHandle (GetCurrentProcess (), + (HANDLE) _get_osfhandle (fd), + GetCurrentProcess (), + &h, + 0, + FALSE, + DUPLICATE_SAME_ACCESS)) { + tiff = TIFFFdOpen ((intptr_t) h, "libpixbuf-tiff", "r"); + if (tiff == NULL) + CloseHandle (h); + } + } +#endif if (!tiff) { g_set_error_literal (error, |