windowscodecs: Workaround libtiff bug when it defines toff_t as 32-bit for 32-bit builds. Take 3.

Dmitry Timoshkov dmitry at baikal.ru
Wed Jul 31 22:34:54 CDT 2013


---
 dlls/windowscodecs/tiffformat.c | 50 ++++++++++++++++++++++++++++++++++++-----
 1 file changed, 44 insertions(+), 6 deletions(-)

diff --git a/dlls/windowscodecs/tiffformat.c b/dlls/windowscodecs/tiffformat.c
index 62f1ad7..fbbdde2 100644
--- a/dlls/windowscodecs/tiffformat.c
+++ b/dlls/windowscodecs/tiffformat.c
@@ -142,7 +142,8 @@ static tsize_t tiff_stream_write(thandle_t client_data, tdata_t data, tsize_t si
     return bytes_written;
 }
 
-static toff_t tiff_stream_seek(thandle_t client_data, toff_t offset, int whence)
+/* libtiff 4.x compatible callbacks */
+static UINT64 tiff_stream_seek(thandle_t client_data, UINT64 offset, int whence)
 {
     IStream *stream = (IStream*)client_data;
     LARGE_INTEGER move;
@@ -178,7 +179,7 @@ static int tiff_stream_close(thandle_t client_data)
     return 0;
 }
 
-static toff_t tiff_stream_size(thandle_t client_data)
+static UINT64 tiff_stream_size(thandle_t client_data)
 {
     IStream *stream = (IStream*)client_data;
     STATSTG statstg;
@@ -190,17 +191,41 @@ static toff_t tiff_stream_size(thandle_t client_data)
     else return -1;
 }
 
-static int tiff_stream_map(thandle_t client_data, tdata_t *addr, toff_t *size)
+static int tiff_stream_map(thandle_t client_data, tdata_t *addr, UINT64 *size)
 {
     /* Cannot mmap streams */
     return 0;
 }
 
-static void tiff_stream_unmap(thandle_t client_data, tdata_t addr, toff_t size)
+static void tiff_stream_unmap(thandle_t client_data, tdata_t addr, UINT64 size)
 {
     /* No need to ever do this, since we can't map things. */
 }
 
+#ifndef TIFF_UINT64_T
+/* libtiff 3.x compatible callbacks */
+static toff_t tiff_stream_seek_v3(thandle_t client_data, toff_t offset, int whence)
+{
+    return tiff_stream_seek(client_data, offset, whence);
+}
+
+static toff_t tiff_stream_size_v3(thandle_t client_data)
+{
+    return tiff_stream_size(client_data);
+}
+
+static int tiff_stream_map_v3(thandle_t client_data, tdata_t *addr, toff_t *size)
+{
+    /* Cannot mmap streams */
+    return 0;
+}
+
+static void tiff_stream_unmap_v3(thandle_t client_data, tdata_t addr, toff_t size)
+{
+    /* No need to ever do this, since we can't map things. */
+}
+#endif /* TIFF_UINT64_T */
+
 static TIFF* tiff_open_stream(IStream *stream, const char *mode)
 {
     LARGE_INTEGER zero;
@@ -208,9 +233,22 @@ static TIFF* tiff_open_stream(IStream *stream, const char *mode)
     zero.QuadPart = 0;
     IStream_Seek(stream, zero, STREAM_SEEK_SET, NULL);
 
+    /* Workaround for broken libtiff 4.x headers on some 64-bit hosts which
+     * define TIFF_UINT64_T/toff_t as 32-bit for 32-bit builds, while they
+     * are supposed to be always 64-bit.
+     * TIFF_UINT64_T doesn't exist in libtiff 3.x, it was introduced in 4.x.
+     */
+#ifdef TIFF_UINT64_T
+    /* libtiff 4.x */
+    return pTIFFClientOpen("<IStream object>", mode, stream, tiff_stream_read,
+        tiff_stream_write, (void *)tiff_stream_seek, tiff_stream_close,
+        (void *)tiff_stream_size, (void *)tiff_stream_map, (void *)tiff_stream_unmap);
+#else
+    /* libtiff 3.x */
     return pTIFFClientOpen("<IStream object>", mode, stream, tiff_stream_read,
-        tiff_stream_write, tiff_stream_seek, tiff_stream_close,
-        tiff_stream_size, tiff_stream_map, tiff_stream_unmap);
+        tiff_stream_write, tiff_stream_seek_v3, tiff_stream_close,
+        tiff_stream_size_v3, tiff_stream_map_v3, tiff_stream_unmap_v3);
+#endif
 }
 
 typedef struct {
-- 
1.8.3.3




More information about the wine-patches mailing list