[MLton-commit] r4641

Wesley Terpstra MLton@mlton.org
Sat, 10 Jun 2006 13:28:03 -0700


Correct a (very) unportable assumption that read/write can service large requests. I'm amazed that linux was able to do this. It broke on MinGW
----------------------------------------------------------------------

U   mlton/branches/on-20050822-x86_64-branch/runtime/util/safe.h

----------------------------------------------------------------------

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/util/safe.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/util/safe.h	2006-06-09 03:09:03 UTC (rev 4640)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/util/safe.h	2006-06-10 20:28:00 UTC (rev 4641)
@@ -54,11 +54,11 @@
 
 static inline void read_safe (int fd, void *buf, size_t size) {
   ssize_t res;
+  size_t offset;
 
-  if (0 == size) return;
-  res = read (fd, buf, size);
-  if (res == -1 or (size_t)res != size)
-    diee ("read (_, _, _) failed.\n");
+  for (offset = 0; offset < size; offset += res)
+    if (0 >= (res = read (fd, (unsigned char*)buf+offset, size-offset)))
+      diee ("read (_, _, _) failed.\n");
 }
 
 static inline void unlink_safe (const char *pathname) {
@@ -72,9 +72,9 @@
 
 static inline void write_safe (int fd, const void *buf, size_t size) {
   ssize_t res;
+  size_t offset;
 
-  if (0 == size) return;
-  res = write (fd, buf, size);
-  if (res == -1 or (size_t)res != size)
-    diee ("write (_, _, _) failed.\n");
+  for (offset = 0; offset < size; offset += res)
+    if (0 >= (res = write (fd, (const unsigned char*)buf+offset, size-offset)))
+      diee ("write (_, _, _) failed.\n");
 }