shithub: mc

Download patch

ref: 3de36cf522da6e8fdb102fb1169465cbbabb3df4
parent: 3792aa38235a273f449d25c4fe813de01bce3093
author: Ori Bernstein <ori@eigenstate.org>
date: Wed Jan 20 20:29:25 EST 2016

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.

--- a/lib/bio/bio.myr
+++ b/lib/bio/bio.myr
@@ -170,7 +170,7 @@
 	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
@@ -191,6 +191,16 @@
 	/* Clear the error state so we can retry */
 	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")
 	/* 
--- a/mk/c.mk
+++ b/mk/c.mk
@@ -9,7 +9,7 @@
 _LIBPATHS=$(addprefix -l, $(patsubst lib%.a,%,$(notdir $(DEPS)))) $(_PCLIBS)
 
 # yeah, I should probably remove -Werror, but it's nice for developing alone.
-CFLAGS += -Wall -Wextra -Werror -Wno-unused-parameter -Wno-missing-field-initializers -Wno-sign-compare -Wno-array-bounds -g -O0
+CFLAGS += -Wall -Wextra -Werror -Wno-unused-parameter -Wno-missing-field-initializers -Wno-sign-compare -Wno-array-bounds -g -O2
 CFLAGS += -MMD -MP -MF .deps/$(subst /,-,$*).d
 
 LIB ?= $(INSTLIB)