diff --git a/lib/modules/Stdio.pmod b/lib/modules/Stdio.pmod
index 3fbec137dc430365ee012ce7abf9ee33cfbe2ee6..4ea39de0334c5a81eb2ba15306d0a3a4d1875fc4 100644
--- a/lib/modules/Stdio.pmod
+++ b/lib/modules/Stdio.pmod
@@ -353,11 +353,19 @@ class FILE {
 	return file::write(sprintf(fmt,@data));
     }
     
-    string read(int bytes)
+    string read(int|void bytes)
     {
+      if (!query_num_arg()) {
+	bytes = 0x7fffffff;
+      }
       while(strlen(b) - bpos < bytes)
-	if(!get_data())
-	  break;
+	if(!get_data()) {
+	  // EOF.
+	  string res = b[bpos..];
+	  b = "";
+	  bpos = 0;
+	  return res;
+	}
 
       return extract(bytes);
     }