ref: a2f4956537807af8c698423f25b9b6de7ab66c1f
parent: feffe0d81fe8bc1d19f5f2305e09c08f70d4a620
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Jul 23 18:31:58 EDT 2017
Add back error signalling on close.
--- a/lib/bio/bio.myr
+++ b/lib/bio/bio.myr
@@ -14,7 +14,7 @@
read : (buf : byte[:] -> std.result(std.size, std.errno))
write : (buf : byte[:] -> std.result(std.size, std.errno))
seek : (idx : std.off -> std.result(std.off, std.errno))
- close : (-> void)
+ close : (-> bool)
/* read buffer */
rbuf : byte[:]
@@ -30,7 +30,7 @@
read : (buf : byte[:] -> std.result(std.size, std.errno))
write : (buf : byte[:] -> std.result(std.size, std.errno))
seek : (idx : std.off -> std.result(std.off, std.errno))
- close : (-> void)
+ close : (-> bool)
;;
type status(@a) = union
@@ -52,7 +52,7 @@
const open : (path : byte[:], mode : mode -> std.result(file#, byte[:]))
const dial : (srv : byte[:], mode : mode -> std.result(file#, byte[:]))
const create : (path : byte[:], mode : mode, perm : int -> std.result(file#, byte[:]))
- const close : (f : file# -> void)
+ const close : (f : file# -> bool)
const free : (f : file# -> void)
/* basic i/o. Returns sub-buffer when applicable. */
@@ -94,10 +94,10 @@
/* Creates a file from an fd, opened in the given mode. */
const mkfile = {fd, mode
-> mk(mode, [
- .read = {buf; -> std.read(fd, buf)},
- .write = {buf; -> std.write(fd, buf)},
- .seek = {off; -> std.seek(fd, off, std.Seekset)},
- .close = {; std.close(fd)},
+ .read = {buf; -> std.read(fd, buf)},
+ .write = {buf; -> std.write(fd, buf)},
+ .seek = {off; -> std.seek(fd, off, std.Seekset)},
+ .close = {; -> std.close(fd) >= 0},
])
}
@@ -167,9 +167,12 @@
/* closes a file, flushing it to the output fd */
const close = {f
- flush(f)
- f.close()
+ var ok
+
+ ok = flush(f)
+ ok = ok && f.close()
_free(f)
+ -> ok
}
const free = {f
--- a/lib/bio/mem.myr
+++ b/lib/bio/mem.myr
@@ -22,7 +22,7 @@
.read = {buf; -> memread(mem, buf)},
.write = {buf; -> memwrite(mem, buf)},
.seek = {off; -> memseek(mem, off)},
- .close = {; std.free(mem)},
+ .close = {; std.free(mem); -> true},
])
}