[MLton-commit] r5001

Stephen Weeks sweeks at mlton.org
Thu Dec 28 12:27:18 PST 2006


Better error message when fread_safe fails.

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

U   mlton/trunk/runtime/util/safe.h

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

Modified: mlton/trunk/runtime/util/safe.h
===================================================================
--- mlton/trunk/runtime/util/safe.h	2006-12-28 18:36:31 UTC (rev 5000)
+++ mlton/trunk/runtime/util/safe.h	2006-12-28 20:27:17 UTC (rev 5001)
@@ -47,9 +47,14 @@
   size_t res;
 
   res = fread (buf, size, count, f);
-  if (res != count)
-    diee ("fread (_, %zu, %zu, _) failed (only read %zu).\n",
-          size, count, res);
+  if (res != count) {
+    if (feof (f))
+       fprintf (stderr, "eof\n");
+    else
+       fprintf (stderr, "errno = %d\n", ferror (f));  
+    diee ("fread ("FMTPTR", %zu, %zu, _) failed (only read %zu).\n",
+          (uintptr_t)buf, size, count, res);
+  }
 }
 
 static inline void fwrite_safe (const void *buf, size_t size, size_t count, FILE *f) {




More information about the MLton-commit mailing list