diff -urN tiff.orig/dirread.c tiff/dirread.c
--- tiff.orig/dirread.c	Sat Feb 02 20:52:59 2013
+++ tiff/dirread.c	Sat Feb 02 20:52:59 2013
@@ -2216,7 +2216,7 @@
 		case TIFF_FLOAT:
 			if (tif->tif_flags&TIFF_SWAB)
 				TIFFSwabArrayOfLong((uint32*)origdata,count);  
-			TIFFCvtIEEEDoubleToNative(tif,count,(float*)origdata);
+			TIFFCvtIEEEFloatToNative(tif,count,(float*)origdata);
 			*value=(float*)origdata;
 			return(TIFFReadDirEntryErrOk);
 	}
@@ -3194,11 +3194,7 @@
 /*
  * Largest 32-bit unsigned integer value.
  */
-#if defined(__WIN32__) && defined(_MSC_VER)
-# define TIFF_UINT32_MAX 0xFFFFFFFFI64
-#else
-# define TIFF_UINT32_MAX 0xFFFFFFFFLL
-#endif
+#define TIFF_UINT32_MAX UINT32_MAX
 
 static enum TIFFReadDirEntryErr
 TIFFReadDirEntryCheckRangeLongLong8(uint64 value)
@@ -3286,11 +3282,7 @@
 /*
  * Largest 64-bit signed integer value.
  */
-#if defined(__WIN32__) && defined(_MSC_VER)
-# define TIFF_INT64_MAX 0x7FFFFFFFFFFFFFFFI64
-#else
-# define TIFF_INT64_MAX 0x7FFFFFFFFFFFFFFFLL
-#endif
+#define TIFF_INT64_MAX INT64_MAX
 
 static enum TIFFReadDirEntryErr
 TIFFReadDirEntryCheckRangeSlong8Long8(uint64 value)
diff -urN tiff.orig/dirwrite.c tiff/dirwrite.c
--- tiff.orig/dirwrite.c	Sat Feb 02 20:52:59 2013
+++ tiff/dirwrite.c	Sat Feb 02 20:52:59 2013
@@ -2238,7 +2238,7 @@
 {
 	assert(count<0x40000000);
 	assert(sizeof(float)==4);
-	TIFFCvtNativeToIEEEFloat(tif,count,&value);
+	TIFFCvtNativeToIEEEFloat(tif,count,value);
 	if (tif->tif_flags&TIFF_SWAB)
 		TIFFSwabArrayOfFloat(value,count);
 	return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_FLOAT,count,count*4,value));
@@ -2263,7 +2263,7 @@
 {
 	assert(count<0x20000000);
 	assert(sizeof(double)==8);
-	TIFFCvtNativeToIEEEDouble(tif,count,&value);
+	TIFFCvtNativeToIEEEDouble(tif,count,value);
 	if (tif->tif_flags&TIFF_SWAB)
 		TIFFSwabArrayOfDouble(value,count);
 	return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_DOUBLE,count,count*8,value));
diff -urN tiff.orig/dumpmode.c tiff/dumpmode.c
--- tiff.orig/dumpmode.c	Sat Feb 02 20:52:59 2013
+++ tiff/dumpmode.c	Sat Feb 02 20:52:59 2013
@@ -80,19 +80,11 @@
 	static const char module[] = "DumpModeDecode";
 	(void) s;
 	if (tif->tif_rawcc < cc) {
-#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
 		TIFFErrorExt(tif->tif_clientdata, module,
-"Not enough data for scanline %lu, expected a request for at most %I64d bytes, got a request for %I64d bytes",
+"Not enough data for scanline %lu, expected a request for at most " TIFF_INT64_FORMAT " bytes, got a request for " TIFF_INT64_FORMAT " bytes",
 		             (unsigned long) tif->tif_row,
-		             (signed __int64) tif->tif_rawcc,
-		             (signed __int64) cc);
-#else
-		TIFFErrorExt(tif->tif_clientdata, module,
-"Not enough data for scanline %lu, expected a request for at most %lld bytes, got a request for %lld bytes",
-		             (unsigned long) tif->tif_row,
-		             (signed long long) tif->tif_rawcc,
-		             (signed long long) cc);
-#endif
+		             (TIFF_INT64_T) tif->tif_rawcc,
+		             (TIFF_INT64_T) cc);
 		return (0);
 	}
 	/*
diff -urN tiff.orig/luv.c tiff/luv.c
--- tiff.orig/luv.c	Sat Feb 02 20:52:59 2013
+++ tiff/luv.c	Sat Feb 02 20:52:59 2013
@@ -224,17 +224,10 @@
 					tp[i++] |= (int16)*bp++ << shft;
 			}
 		if (i != npixels) {
-#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
 			TIFFErrorExt(tif->tif_clientdata, module,
-			    "Not enough data at row %lu (short %I64d pixels)",
+			    "Not enough data at row %lu (short " TIFF_UINT64_FORMAT " pixels)",
 				     (unsigned long) tif->tif_row,
-				     (unsigned __int64) (npixels - i));
-#else
-			TIFFErrorExt(tif->tif_clientdata, module,
-			    "Not enough data at row %lu (short %llu pixels)",
-				     (unsigned long) tif->tif_row,
-				     (unsigned long long) (npixels - i));
-#endif
+				     (TIFF_UINT64_T) (npixels - i));
 			tif->tif_rawcp = (uint8*) bp;
 			tif->tif_rawcc = cc;
 			return (0);
@@ -282,17 +275,10 @@
 	tif->tif_rawcp = (uint8*) bp;
 	tif->tif_rawcc = cc;
 	if (i != npixels) {
-#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
-		TIFFErrorExt(tif->tif_clientdata, module,
-			"Not enough data at row %lu (short %I64d pixels)",
-			     (unsigned long) tif->tif_row,
-			     (unsigned __int64) (npixels - i));
-#else
 		TIFFErrorExt(tif->tif_clientdata, module,
-			"Not enough data at row %lu (short %llu pixels)",
+			"Not enough data at row %lu (short " TIFF_UINT64_FORMAT " pixels)",
 			     (unsigned long) tif->tif_row,
-			     (unsigned long long) (npixels - i));
-#endif
+			     (TIFF_UINT64_T) (npixels - i));
 		return (0);
 	}
 	(*sp->tfunc)(sp, op, npixels);
@@ -347,17 +333,10 @@
 					tp[i++] |= (uint32)*bp++ << shft;
 			}
 		if (i != npixels) {
-#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
-			TIFFErrorExt(tif->tif_clientdata, module,
-			"Not enough data at row %lu (short %I64d pixels)",
-				     (unsigned long) tif->tif_row,
-				     (unsigned __int64) (npixels - i));
-#else
 			TIFFErrorExt(tif->tif_clientdata, module,
-			"Not enough data at row %lu (short %llu pixels)",
+			"Not enough data at row %lu (short " TIFF_UINT64_FORMAT " pixels)",
 				     (unsigned long) tif->tif_row,
-				     (unsigned long long) (npixels - i));
-#endif
+				     (TIFF_UINT64_T) (npixels - i));
 			tif->tif_rawcp = (uint8*) bp;
 			tif->tif_rawcc = cc;
 			return (0);
diff -urN tiff.orig/lzw.c tiff/lzw.c
--- tiff.orig/lzw.c	Sat Feb 02 20:52:59 2013
+++ tiff/lzw.c	Sat Feb 02 20:52:59 2013
@@ -549,15 +549,9 @@
 	sp->dec_maxcodep = maxcodep;
 
 	if (occ > 0) {
-#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
 		TIFFErrorExt(tif->tif_clientdata, module,
-			"Not enough data at scanline %d (short %I64d bytes)",
-			     tif->tif_row, (unsigned __int64) occ);
-#else
-		TIFFErrorExt(tif->tif_clientdata, module,
-			"Not enough data at scanline %d (short %llu bytes)",
-			     tif->tif_row, (unsigned long long) occ);
-#endif
+			"Not enough data at scanline %d (short " TIFF_UINT64_FORMAT " bytes)",
+			     tif->tif_row, (TIFF_UINT64_T) occ);
 		return (0);
 	}
 	return (1);
@@ -753,15 +747,9 @@
 	sp->dec_maxcodep = maxcodep;
 
 	if (occ > 0) {
-#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
-		TIFFErrorExt(tif->tif_clientdata, module,
-			"Not enough data at scanline %d (short %I64d bytes)",
-			     tif->tif_row, (unsigned __int64) occ);
-#else
 		TIFFErrorExt(tif->tif_clientdata, module,
-			"Not enough data at scanline %d (short %llu bytes)",
-			     tif->tif_row, (unsigned long long) occ);
-#endif
+			"Not enough data at scanline %d (short " TIFF_UINT64_FORMAT " bytes)",
+			     tif->tif_row, (TIFF_UINT64_T) occ);
 		return (0);
 	}
 	return (1);
diff -urN tiff.orig/print.c tiff/print.c
--- tiff.orig/print.c	Sat Feb 02 20:52:59 2013
+++ tiff/print.c	Sat Feb 02 20:52:59 2013
@@ -98,27 +98,13 @@
 			|| fip->field_type == TIFF_FLOAT)
 			fprintf(fd, "%f", ((float *) raw_data)[j]);
 		else if(fip->field_type == TIFF_LONG8)
-#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
-			fprintf(fd, "%I64u",
-			    (unsigned __int64)((uint64 *) raw_data)[j]);
-#else
-			fprintf(fd, "%llu",
-			    (unsigned long long)((uint64 *) raw_data)[j]);
-#endif
+			fprintf(fd, TIFF_UINT64_FORMAT,
+			    (TIFF_UINT64_T)((uint64 *) raw_data)[j]);
 		else if(fip->field_type == TIFF_SLONG8)
-#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
-			fprintf(fd, "%I64d", (__int64)((int64 *) raw_data)[j]);
-#else
-			fprintf(fd, "%lld", (long long)((int64 *) raw_data)[j]);
-#endif
+			fprintf(fd, TIFF_INT64_FORMAT, (TIFF_INT64_T)((int64 *) raw_data)[j]);
 		else if(fip->field_type == TIFF_IFD8)
-#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
-			fprintf(fd, "0x%I64x",
-				(unsigned __int64)((uint64 *) raw_data)[j]);
-#else
-			fprintf(fd, "0x%llx",
-				(unsigned long long)((uint64 *) raw_data)[j]);
-#endif
+			fprintf(fd, "0x%" HB_PF64 "x",
+				(TIFF_UINT64_T)((uint64 *) raw_data)[j]);
 		else if(fip->field_type == TIFF_FLOAT)
 			fprintf(fd, "%f", ((float *)raw_data)[j]);
 		else if(fip->field_type == TIFF_DOUBLE)
@@ -240,15 +226,9 @@
 	uint16 i;
 	long l, n;
 
-#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
-	fprintf(fd, "TIFF Directory at offset 0x%I64x (%I64u)\n",
-		(unsigned __int64) tif->tif_diroff,
-		(unsigned __int64) tif->tif_diroff);
-#else
-	fprintf(fd, "TIFF Directory at offset 0x%llx (%llu)\n",
-		(unsigned long long) tif->tif_diroff,
-		(unsigned long long) tif->tif_diroff);
-#endif
+	fprintf(fd, "TIFF Directory at offset 0x%" HB_PF64 "x (%" HB_PF64 "u)\n",
+		(TIFF_UINT64_T) tif->tif_diroff,
+		(TIFF_UINT64_T) tif->tif_diroff);
 	if (TIFFFieldSet(tif,FIELD_SUBFILETYPE)) {
 		fprintf(fd, "  Subfile Type:");
 		sep = " ";
@@ -552,13 +532,8 @@
 	if (TIFFFieldSet(tif, FIELD_SUBIFD) && (td->td_subifd)) {
 		fprintf(fd, "  SubIFD Offsets:");
 		for (i = 0; i < td->td_nsubifd; i++)
-#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
-			fprintf(fd, " %5I64u",
-				(unsigned __int64) td->td_subifd[i]);
-#else
-			fprintf(fd, " %5llu",
-				(unsigned long long) td->td_subifd[i]);
-#endif
+			fprintf(fd, " %5" HB_PF64 "u",
+				(TIFF_UINT64_T) td->td_subifd[i]);
 		fputc('\n', fd);
 	}
 
@@ -658,17 +633,10 @@
 		    (long) td->td_nstrips,
 		    isTiled(tif) ? "Tiles" : "Strips");
 		for (s = 0; s < td->td_nstrips; s++)
-#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
-			fprintf(fd, "    %3lu: [%8I64u, %8I64u]\n",
+			fprintf(fd, "    %3lu: [%8" HB_PF64 "u, %8" HB_PF64 "u]\n",
 			    (unsigned long) s,
-			    (unsigned __int64) td->td_stripoffset[s],
-			    (unsigned __int64) td->td_stripbytecount[s]);
-#else
-			fprintf(fd, "    %3lu: [%8llu, %8llu]\n",
-			    (unsigned long) s,
-			    (unsigned long long) td->td_stripoffset[s],
-			    (unsigned long long) td->td_stripbytecount[s]);
-#endif
+			    (TIFF_UINT64_T) td->td_stripoffset[s],
+			    (TIFF_UINT64_T) td->td_stripbytecount[s]);
 	}
 }
 
diff -urN tiff.orig/read.c tiff/read.c
--- tiff.orig/read.c	Sat Feb 02 20:52:59 2013
+++ tiff/read.c	Sat Feb 02 20:52:59 2013
@@ -125,19 +125,11 @@
         cc = TIFFReadFile(tif, tif->tif_rawdata + unused_data, to_read);
 
         if (cc != to_read) {
-#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
                 TIFFErrorExt(tif->tif_clientdata, module,
-                             "Read error at scanline %lu; got %I64u bytes, expected %I64u",
+                             "Read error at scanline %lu; got " TIFF_UINT64_FORMAT " bytes, expected " TIFF_UINT64_FORMAT,
                              (unsigned long) tif->tif_row,
-                             (unsigned __int64) cc,
-                             (unsigned __int64) to_read);
-#else
-                TIFFErrorExt(tif->tif_clientdata, module,
-                             "Read error at scanline %lu; got %llu bytes, expected %llu",
-                             (unsigned long) tif->tif_row,
-                             (unsigned long long) cc,
-                             (unsigned long long) to_read);
-#endif
+                             (TIFF_UINT64_T) cc,
+                             (TIFF_UINT64_T) to_read);
                 return 0;
         }
         
@@ -381,19 +373,11 @@
 		}
 		cc = TIFFReadFile(tif, buf, size);
 		if (cc != size) {
-#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
 			TIFFErrorExt(tif->tif_clientdata, module,
-		"Read error at scanline %lu; got %I64u bytes, expected %I64u",
+		"Read error at scanline %lu; got " TIFF_UINT64_FORMAT " bytes, expected " TIFF_UINT64_FORMAT,
 				     (unsigned long) tif->tif_row,
-				     (unsigned __int64) cc,
-				     (unsigned __int64) size);
-#else
-			TIFFErrorExt(tif->tif_clientdata, module,
-		"Read error at scanline %lu; got %llu bytes, expected %llu",
-				     (unsigned long) tif->tif_row,
-				     (unsigned long long) cc,
-				     (unsigned long long) size);
-#endif
+				     (TIFF_UINT64_T) cc,
+				     (TIFF_UINT64_T) size);
 			return ((tmsize_t)(-1));
 		}
 	} else {
@@ -408,21 +392,12 @@
 		else
 			n=size;
 		if (n!=size) {
-#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
 			TIFFErrorExt(tif->tif_clientdata, module,
-	"Read error at scanline %lu, strip %lu; got %I64u bytes, expected %I64u",
+	"Read error at scanline %lu, strip %lu; got " TIFF_UINT64_FORMAT " bytes, expected " TIFF_UINT64_FORMAT,
 				     (unsigned long) tif->tif_row,
 				     (unsigned long) strip,
-				     (unsigned __int64) n,
-				     (unsigned __int64) size);
-#else
-			TIFFErrorExt(tif->tif_clientdata, module,
-	"Read error at scanline %lu, strip %lu; got %llu bytes, expected %llu",
-				     (unsigned long) tif->tif_row,
-				     (unsigned long) strip,
-				     (unsigned long long) n,
-				     (unsigned long long) size);
-#endif
+				     (TIFF_UINT64_T) n,
+				     (TIFF_UINT64_T) size);
 			return ((tmsize_t)(-1));
 		}
 		_TIFFmemcpy(buf, tif->tif_base + ma,
@@ -459,17 +434,10 @@
 	}
 	bytecount = td->td_stripbytecount[strip];
 	if (bytecount <= 0) {
-#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
-		TIFFErrorExt(tif->tif_clientdata, module,
-			     "%I64u: Invalid strip byte count, strip %lu",
-			     (unsigned __int64) bytecount,
-			     (unsigned long) strip);
-#else
 		TIFFErrorExt(tif->tif_clientdata, module,
-			     "%llu: Invalid strip byte count, strip %lu",
-			     (unsigned long long) bytecount,
+			     TIFF_UINT64_FORMAT ": Invalid strip byte count, strip %lu",
+			     (TIFF_UINT64_T) bytecount,
 			     (unsigned long) strip);
-#endif
 		return ((tmsize_t)(-1));
 	}
 	bytecountm = (tmsize_t)bytecount;
@@ -499,17 +467,10 @@
 	{
 		uint64 bytecount = td->td_stripbytecount[strip];
 		if (bytecount <= 0) {
-#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
 			TIFFErrorExt(tif->tif_clientdata, module,
-				"Invalid strip byte count %I64u, strip %lu",
-				     (unsigned __int64) bytecount,
+				"Invalid strip byte count " TIFF_UINT64_FORMAT ", strip %lu",
+				     (TIFF_UINT64_T) bytecount,
 				     (unsigned long) strip);
-#else
-			TIFFErrorExt(tif->tif_clientdata, module,
-				"Invalid strip byte count %llu, strip %lu",
-				     (unsigned long long) bytecount,
-				     (unsigned long) strip);
-#endif
 			return (0);
 		}
 		if (isMapped(tif) &&
@@ -548,23 +509,13 @@
 				 * it's what would happen if a read were done
 				 * instead.
 				 */
-#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
 				TIFFErrorExt(tif->tif_clientdata, module,
 
 					"Read error on strip %lu; "
-					"got %I64u bytes, expected %I64u",
+					"got " TIFF_UINT64_FORMAT " bytes, expected " TIFF_UINT64_FORMAT,
 					(unsigned long) strip,
-					(unsigned __int64) tif->tif_size - td->td_stripoffset[strip],
-					(unsigned __int64) bytecount);
-#else
-				TIFFErrorExt(tif->tif_clientdata, module,
-
-					"Read error on strip %lu; "
-					"got %llu bytes, expected %llu",
-					(unsigned long) strip,
-					(unsigned long long) tif->tif_size - td->td_stripoffset[strip],
-					(unsigned long long) bytecount);
-#endif
+					(TIFF_UINT64_T) tif->tif_size - td->td_stripoffset[strip],
+					(TIFF_UINT64_T) bytecount);
 				tif->tif_curstrip = NOSTRIP;
 				return (0);
 			}
@@ -695,21 +646,12 @@
 		}
 		cc = TIFFReadFile(tif, buf, size);
 		if (cc != size) {
-#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
 			TIFFErrorExt(tif->tif_clientdata, module,
-	"Read error at row %lu, col %lu; got %I64u bytes, expected %I64u",
+	"Read error at row %lu, col %lu; got " TIFF_UINT64_FORMAT " bytes, expected " TIFF_UINT64_FORMAT,
 				     (unsigned long) tif->tif_row,
 				     (unsigned long) tif->tif_col,
-				     (unsigned __int64) cc,
-				     (unsigned __int64) size);
-#else
-			TIFFErrorExt(tif->tif_clientdata, module,
-	"Read error at row %lu, col %lu; got %llu bytes, expected %llu",
-				     (unsigned long) tif->tif_row,
-				     (unsigned long) tif->tif_col,
-				     (unsigned long long) cc,
-				     (unsigned long long) size);
-#endif
+				     (TIFF_UINT64_T) cc,
+				     (TIFF_UINT64_T) size);
 			return ((tmsize_t)(-1));
 		}
 	} else {
@@ -724,23 +666,13 @@
 		else
 			n=size;
 		if (n!=size) {
-#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
 			TIFFErrorExt(tif->tif_clientdata, module,
-"Read error at row %lu, col %lu, tile %lu; got %I64u bytes, expected %I64u",
+"Read error at row %lu, col %lu, tile %lu; got " TIFF_UINT64_FORMAT " bytes, expected " TIFF_UINT64_FORMAT,
 				     (unsigned long) tif->tif_row,
 				     (unsigned long) tif->tif_col,
 				     (unsigned long) tile,
-				     (unsigned __int64) n,
-				     (unsigned __int64) size);
-#else
-			TIFFErrorExt(tif->tif_clientdata, module,
-"Read error at row %lu, col %lu, tile %lu; got %llu bytes, expected %llu",
-				     (unsigned long) tif->tif_row,
-				     (unsigned long) tif->tif_col,
-				     (unsigned long) tile,
-				     (unsigned long long) n,
-				     (unsigned long long) size);
-#endif
+				     (TIFF_UINT64_T) n,
+				     (TIFF_UINT64_T) size);
 			return ((tmsize_t)(-1));
 		}
 		_TIFFmemcpy(buf, tif->tif_base + ma, size);
@@ -802,17 +734,10 @@
 	{
 		uint64 bytecount = td->td_stripbytecount[tile];
 		if (bytecount <= 0) {
-#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
 			TIFFErrorExt(tif->tif_clientdata, module,
-				"%I64u: Invalid tile byte count, tile %lu",
-				     (unsigned __int64) bytecount,
+				TIFF_UINT64_FORMAT ": Invalid tile byte count, tile %lu",
+				     (TIFF_UINT64_T) bytecount,
 				     (unsigned long) tile);
-#else
-			TIFFErrorExt(tif->tif_clientdata, module,
-				"%llu: Invalid tile byte count, tile %lu",
-				     (unsigned long long) bytecount,
-				     (unsigned long) tile);
-#endif
 			return (0);
 		}
 		if (isMapped(tif) &&
diff -urN tiff.orig/strip.c tiff/strip.c
--- tiff.orig/strip.c	Sat Feb 02 20:52:59 2013
+++ tiff/strip.c	Sat Feb 02 20:52:59 2013
@@ -154,17 +154,10 @@
 
 	if (bytecount == 0)
 	{
-#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
 		TIFFErrorExt(tif->tif_clientdata, module,
-			     "%I64u: Invalid strip byte count, strip %lu",
-			     (unsigned __int64) bytecount,
+			     TIFF_UINT64_FORMAT ": Invalid strip byte count, strip %lu",
+			     (TIFF_UINT64_T) bytecount,
 			     (unsigned long) strip);
-#else
-		TIFFErrorExt(tif->tif_clientdata, module,
-			     "%llu: Invalid strip byte count, strip %lu",
-			     (unsigned long long) bytecount,
-			     (unsigned long) strip);
-#endif
 		bytecount = (uint64) -1;
 	}
 
diff -urN tiff.orig/thunder.c tiff/thunder.c
--- tiff.orig/thunder.c	Sat Feb 02 20:52:59 2013
+++ tiff/thunder.c	Sat Feb 02 20:52:59 2013
@@ -143,21 +143,12 @@
 	tif->tif_rawcp = (uint8*) bp;
 	tif->tif_rawcc = cc;
 	if (npixels != maxpixels) {
-#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
 		TIFFErrorExt(tif->tif_clientdata, module,
-			     "%s data at scanline %lu (%I64u != %I64u)",
+			     "%s data at scanline %lu (" TIFF_UINT64_FORMAT " != " TIFF_UINT64_FORMAT ")",
 			     npixels < maxpixels ? "Not enough" : "Too much",
 			     (unsigned long) tif->tif_row,
-			     (unsigned __int64) npixels,
-			     (unsigned __int64) maxpixels);
-#else
-		TIFFErrorExt(tif->tif_clientdata, module,
-			     "%s data at scanline %lu (%llu != %llu)",
-			     npixels < maxpixels ? "Not enough" : "Too much",
-			     (unsigned long) tif->tif_row,
-			     (unsigned long long) npixels,
-			     (unsigned long long) maxpixels);
-#endif
+			     (TIFF_UINT64_T) npixels,
+			     (TIFF_UINT64_T) maxpixels);
 		return (0);
 	}
 
diff -urN tiff.orig/tiffconf.h tiff/tiffconf.h
--- tiff.orig/tiffconf.h	Sat Feb 02 20:52:59 2013
+++ tiff/tiffconf.h	Sat Feb 02 20:52:59 2013
@@ -7,44 +7,65 @@
 #ifndef _TIFFCONF_
 #define _TIFFCONF_
 
+#include "hbdefs.h"
+#include "hb_io.h"
+
 /* Signed 16-bit type */
-#undef TIFF_INT16_T
+#define TIFF_INT16_T HB_I16
 
 /* Signed 32-bit type */
-#undef TIFF_INT32_T
+#define TIFF_INT32_T HB_I32
 
 /* Signed 64-bit type */
-#undef TIFF_INT64_T
+#define TIFF_INT64_T HB_I64
 
 /* Signed 8-bit type */
-#undef TIFF_INT8_T
+#define TIFF_INT8_T HB_I8
 
 /* Unsigned 16-bit type */
-#undef TIFF_UINT16_T
+#define TIFF_UINT16_T HB_U16
 
 /* Unsigned 32-bit type */
-#undef TIFF_UINT32_T
+#define TIFF_UINT32_T HB_U32
 
 /* Unsigned 64-bit type */
-#undef TIFF_UINT64_T
+#define TIFF_UINT64_T HB_U64
 
 /* Unsigned 8-bit type */
-#undef TIFF_UINT8_T
+#define TIFF_UINT8_T HB_U8
 
 /* Signed size type */
-#undef TIFF_SSIZE_T
+#define TIFF_SSIZE_T HB_ISIZ
 
 /* Pointer difference type */
-#undef TIFF_PTRDIFF_T
+#define TIFF_PTRDIFF_T HB_PTRDIFF
+
+/* Signed 32-bit type formatter */
+#define TIFF_INT32_FORMAT "%d"
+
+/* Unsigned 32-bit type formatter */
+#define TIFF_UINT32_FORMAT "%u"
+
+/* Signed 64-bit type formatter */
+#define TIFF_INT64_FORMAT "%" HB_PF64 "d"
+
+/* Unsigned 64-bit type formatter */
+#define TIFF_UINT64_FORMAT "%" HB_PF64 "u"
+
+/* Signed size type formatter */
+#define TIFF_SSIZE_FORMAT "%" HB_PFS "d"
+
+/* file handler */
+#define TIFF_FILE_HANDLE HB_FHANDLE
 
 /* Define to 1 if the system has the type `int16'. */
-#undef HAVE_INT16
+#define HAVE_INT16
 
 /* Define to 1 if the system has the type `int32'. */
-#undef HAVE_INT32
+#define HAVE_INT32
 
 /* Define to 1 if the system has the type `int8'. */
-#undef HAVE_INT8
+#define HAVE_INT8
 
 /* Compatibility stuff. */
 
@@ -53,17 +74,29 @@
 #undef HAVE_IEEEFP
 
 /* Set the native cpu bit order (FILLORDER_LSB2MSB or FILLORDER_MSB2LSB) */
-#undef HOST_FILLORDER
+#if defined( HB_BIG_ENDIAN )
+   #define HOST_FILLORDER FILLORDER_LSB2MSB
+#elif defined( HB_LITTLE_ENDIAN )
+   #define HOST_FILLORDER FILLORDER_MSB2LSB
+#else
+   #undef HOST_FILLORDER
+#endif
 
 /* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian
    (Intel) */
-#undef HOST_BIGENDIAN
+#if defined( HB_BIG_ENDIAN )
+   #define HOST_BIGENDIAN
+#endif
 
+#if 0
 /* Support CCITT Group 3 & 4 algorithms */
 #undef CCITT_SUPPORT
+#endif
 
+#if 0
 /* Support JPEG compression (requires IJG JPEG library) */
 #undef JPEG_SUPPORT
+#endif
 
 /* Support JBIG compression (requires JBIG-KIT library) */
 #undef JBIG_SUPPORT
@@ -71,11 +104,15 @@
 /* Support LogLuv high dynamic range encoding */
 #undef LOGLUV_SUPPORT
 
+#if 0
 /* Support LZW algorithm */
 #undef LZW_SUPPORT
+#endif
 
+#if 0
 /* Support NeXT 2-bit RLE algorithm */
 #undef NEXT_SUPPORT
+#endif
 
 /* Support Old JPEG compresson (read contrib/ojpeg/README first! Compilation
    fails with unpatched IJG JPEG library) */
@@ -90,8 +127,10 @@
 /* Support ThunderScan 4-bit RLE algorithm */
 #undef THUNDER_SUPPORT
 
+#if 0
 /* Support Deflate compression */
 #undef ZIP_SUPPORT
+#endif
 
 /* Support strip chopping (whether or not to convert single-strip uncompressed
    images to mutiple strips of ~8Kb to reduce memory usage) */
@@ -123,5 +162,23 @@
 #define ICC_SUPPORT
 #define PHOTOSHOP_SUPPORT
 #define IPTC_SUPPORT
+
+#if ! defined( HB_OS_UNIX )
+#ifndef O_RDONLY
+#define O_RDONLY 0
+#endif
+#ifndef O_RDWR
+#define O_RDWR 2
+#endif
+#ifndef O_WRONLY
+#define O_WRONLY 000001
+#endif
+#ifndef O_CREAT
+#define O_CREAT 000100
+#endif
+#ifndef O_TRUNC
+#define O_TRUNC 001000
+#endif
+#endif
 
 #endif /* _TIFFCONF_ */
diff -urN tiff.orig/tiffio.h tiff/tiffio.h
--- tiff.orig/tiffio.h	Sat Feb 02 20:52:59 2013
+++ tiff/tiffio.h	Sat Feb 02 20:52:59 2013
@@ -102,6 +102,8 @@
 # else
 typedef HFILE thandle_t;       /* client data handle */
 # endif /* __WIN32__ */
+#elif defined(TIFF_FILE_HANDLE)
+typedef TIFF_FILE_HANDLE thandle_t; /* client data handle */
 #else
 typedef void* thandle_t;       /* client data handle */
 #endif /* USE_WIN32_FILEIO */
diff -urN tiff.orig/tiffiop.h tiff/tiffiop.h
--- tiff.orig/tiffiop.h	Sat Feb 02 20:52:59 2013
+++ tiff/tiffiop.h	Sat Feb 02 20:52:59 2013
@@ -30,7 +30,7 @@
  * ``Library-private'' definitions.
  */
 
-#include "tif_config.h"
+#include "tiffconf.h"
 
 #ifdef HAVE_FCNTL_H
 # include <fcntl.h>
diff -urN tiff.orig/unix.c tiff/unix.c
--- tiff.orig/unix.c	Sat Feb 02 20:52:59 2013
+++ tiff/unix.c	Sat Feb 02 20:52:59 2013
@@ -29,7 +29,7 @@
  * Windows Common RunTime Library.
  */
 
-#include "tif_config.h"
+#include "tiffconf.h"
 
 #ifdef HAVE_SYS_TYPES_H
 # include <sys/types.h>
