[gdk-pixbuf] io-tiff: Correctly work with WIN32-IO version of libtiff
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gdk-pixbuf] io-tiff: Correctly work with WIN32-IO version of libtiff
- Date: Wed, 29 Nov 2017 19:11:24 +0000 (UTC)
commit ce52cefbbc7c6910cd6fd99c7321292b91202009
Author: Руслан Ижбулатов <lrn1986 gmail com>
Date: Sun Oct 1 02:50:54 2017 +0000
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
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 7d055cf..7ca0a56 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,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]