summaryrefslogtreecommitdiff
path: root/lib/bio
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2017-07-23 22:31:58 -0700
committerOri Bernstein <ori@eigenstate.org>2017-07-23 22:31:58 -0700
commita2f4956537807af8c698423f25b9b6de7ab66c1f (patch)
treece99187df681c01125562b02bdf655f8774abf73 /lib/bio
parentfeffe0d81fe8bc1d19f5f2305e09c08f70d4a620 (diff)
downloadmc-a2f4956537807af8c698423f25b9b6de7ab66c1f.tar.gz
Add back error signalling on close.
Diffstat (limited to 'lib/bio')
-rw-r--r--lib/bio/bio.myr21
-rw-r--r--lib/bio/mem.myr2
2 files changed, 13 insertions, 10 deletions
diff --git a/lib/bio/bio.myr b/lib/bio/bio.myr
index 465cc93..e1b18a0 100644
--- a/lib/bio/bio.myr
+++ b/lib/bio/bio.myr
@@ -14,7 +14,7 @@ pkg bio =
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 @@ pkg bio =
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 @@ pkg bio =
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 @@ const Small = 512
/* 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 @@ const sysopen = {path, mode, openmode, perm
/* 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
diff --git a/lib/bio/mem.myr b/lib/bio/mem.myr
index bf89912..bebae73 100644
--- a/lib/bio/mem.myr
+++ b/lib/bio/mem.myr
@@ -22,7 +22,7 @@ const mkmem = {buf
.read = {buf; -> memread(mem, buf)},
.write = {buf; -> memwrite(mem, buf)},
.seek = {off; -> memseek(mem, off)},
- .close = {; std.free(mem)},
+ .close = {; std.free(mem); -> true},
])
}