summaryrefslogtreecommitdiff
path: root/lib/bio
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2016-01-21 01:29:25 -0800
committerOri Bernstein <ori@eigenstate.org>2016-01-21 01:29:25 -0800
commit3de36cf522da6e8fdb102fb1169465cbbabb3df4 (patch)
treef19c918569df386af8354c3053b8a20f486eb3ed /lib/bio
parent3792aa38235a273f449d25c4fe813de01bce3093 (diff)
downloadmc-3de36cf522da6e8fdb102fb1169465cbbabb3df4.tar.gz
bio.read(f, [][:]) should succeed without Eof.
A read of 0 could be from two cases: EOF, or a zero byte length request. Since a zero byte length request can always be satisifed, it probably shouldn't be an EOF. Especially since this sort of request can show up in the middle of a file. Yes, this is a bit strange to me too, but it seems the most consistent.
Diffstat (limited to 'lib/bio')
-rw-r--r--lib/bio/bio.myr12
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/bio/bio.myr b/lib/bio/bio.myr
index 87731dd..6ca56d9 100644
--- a/lib/bio/bio.myr
+++ b/lib/bio/bio.myr
@@ -170,7 +170,7 @@ const write = {f, src
Tack small writes onto the buffer end. Big ones
flush the buffer and then go right to kernel.
*/
- if src.len < (f.wbuf.len - f.wend)
+ if src.len <= (f.wbuf.len - f.wend)
std.slcp(f.wbuf[f.wend:f.wend+src.len], src)
f.wend += src.len
-> `Ok src.len
@@ -192,6 +192,16 @@ const read = {f, dst
if f.lasterr != 0
-> `Err geterr(f)
;;
+
+ /*
+ a zero byte read always succeeds, reading 0 bytes; since
+ there are an infinite number of zero byte reads you can do
+ from anywhere in the file, including the end, this is not
+ an EOF condition.
+ */
+ if dst.len == 0
+ -> `Ok dst
+ ;;
std.assert(f.mode & Rd != 0, "File is not in read mode")
/*
* small reads should try to fill, so we don't have to make a