AWARE [SYSTEMS] Imaging expertise for the Delphi developer
AWare Systems, Imaging expertise for the Delphi developer, Home TIFF and LibTiff Mailing List Archive

LibTiff Mailing List

TIFF and LibTiff Mailing List Archive
February 2010

Previous Thread
Next Thread

Previous by Thread
Next by Thread

Previous by Date
Next by Date

Contact

The TIFF Mailing List Homepage
This list is run by Frank Warmerdam
Archive maintained by AWare Systems



Valid HTML 4.01!



Thread

2010.02.26 08:11 "Patch for tif_unix.c", by Eric Doenges
2010.02.26 14:30 "Re: Patch for tif_unix.c", by Edward Lam
2010.02.26 17:05 "Re: Patch for tif_unix.c", by Bob Friesenhahn
2010.02.26 17:43 "Re: Patch for tif_unix.c", by Edward Lam
2010.02.26 18:06 "Re: Patch for tif_unix.c", by Bob Friesenhahn
2010.02.26 19:24 "Re: Patch for tif_unix.c", by Edward Lam
2010.03.02 08:14 "Re: Patch for tif_unix.c", by Eric Doenges
2010.03.02 14:11 "Re: Patch for tif_unix.c", by Toby Thain
2010.03.02 14:53 "Re: Patch for tif_unix.c", by Scott Ribe
2010.03.02 15:42 "Re: Patch for tif_unix.c", by Toby Thain
2010.03.02 15:52 "Re: Patch for tif_unix.c", by Scott Ribe
2010.03.02 16:14 "Re: Patch for tif_unix.c", by Bob Friesenhahn
2010.03.02 16:51 "Re: Patch for tif_unix.c", by Scott Ribe
2010.03.02 16:55 "Re: Patch for tif_unix.c", by Toby Thain
2010.03.02 14:21 "Re: Patch for tif_unix.c", by Edward Lam
2010.03.02 16:05 "Re: Patch for tif_unix.c", by Eric Doenges
2010.03.02 18:13 "Re: Patch for tif_unix.c", by Edward Lam

2010.02.26 08:11 "Patch for tif_unix.c", by Eric Doenges

Hi,

I have a small patch for tif_unix.c that I would like to see included in
libtiff 4.0 if possible. The problem is that tif_unix.c assumes that
read() and write() will be able to read and write the number of
requested bytes in one go. While this assumption seems to hold (for disk
files) on all Unix systems I have ever worked on, it is not guaranteed
by POSIX, and we do have one system (TI TMS320C6X using TI's compiler
and C runtime) where file I/O can only be done in small chunks (256
bytes in this case).

With kind regards,
Eric Dönges
-- 
Dr. Eric Dönges                            doenges@mvtec.com
MVTec Software GmbH | Neherstr. 1 | 81675 München  | Germany
www.mvtec.com | Tel: +49 89 457695-0 | Fax: +49 89 457695-55
Geschäftsführer: Dr. Wolfgang Eckstein, Dr. Olaf Munkelt
Amtsgericht München HRB 114695

Index: libtiff/tif_unix.c
===================================================================
RCS file: /cvs/maptools/cvsroot/libtiff/libtiff/tif_unix.c,v
retrieving revision 1.21
diff -u -r1.21 tif_unix.c
--- libtiff/tif_unix.c	18 Jul 2007 13:46:41 -0000	1.21
+++ libtiff/tif_unix.c	26 Feb 2010 07:49:36 -0000
@@ -58,25 +58,43 @@
 static tmsize_t
 _tiffReadProc(thandle_t fd, void* buf, tmsize_t size)
 {
-	size_t size_io = (size_t) size;
-	if ((tmsize_t) size_io != size)
-	{
-		errno=EINVAL;
-		return (tmsize_t) -1;
-	}
-	return ((tmsize_t) read((int) fd, buf, size_io));
+        size_t bytes, total, size_io = (size_t) size;
+        if ((tmsize_t) size_io != size)
+        {
+                errno=EINVAL;
+                return (tmsize_t) -1;
+        }
+
+        for (total = 0; total < size_io; total += bytes)
+        {
+                if (0 > (bytes = read((int) fd, (char *) buf + total,
+                                      size_io - total)))
+                        return (tmsize_t) -1;
+                else if (0 == bytes)
+                        break;
+        }
+        return (tmsize_t) total;
 }
 
 static tmsize_t
 _tiffWriteProc(thandle_t fd, void* buf, tmsize_t size)
 {
-	size_t size_io = (size_t) size;
-	if ((tmsize_t) size_io != size)
-	{
-		errno=EINVAL;
-		return (tmsize_t) -1;
-	}
-	return ((tmsize_t) write((int) fd, buf, size_io));
+        size_t bytes, total, size_io = (size_t) size;
+        if ((tmsize_t) size_io != size)
+        {
+                errno=EINVAL;
+                return (tmsize_t) -1;
+        }
+
+        for (total = 0; total < size_io; total += bytes)
+        {
+                if (0 > (bytes = write((int) fd, (char *) buf + total,
+                                       size_io - total)))
+                        return (tmsize_t)-1;
+                else if (0 == bytes)
+                        break;
+        }
+        return (tmsize_t) total;
 }
 
 static uint64