summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2014-09-28 23:30:55 -0400
committerOri Bernstein <ori@eigenstate.org>2014-09-28 23:30:55 -0400
commita1371465bd9d282020dfecf230917a9e881a5574 (patch)
tree222b62b87b9ea99986ab11bca6cc9642b41e24f7
parent76c13fb5d6c1ba31a4d930e3db5f5466f263f6fb (diff)
downloadlibbio-a1371465bd9d282020dfecf230917a9e881a5574.tar.gz
Allow for destroying a file without closing.
This is useful for buffered wrappers around FDs.
-rw-r--r--bio.myr11
1 files changed, 10 insertions, 1 deletions
diff --git a/bio.myr b/bio.myr
index 298f1f5..bbcda32 100644
--- a/bio.myr
+++ b/bio.myr
@@ -27,6 +27,7 @@ pkg bio =
const dial : (srv : byte[:], mode : mode -> std.option(file#))
const create : (path : byte[:], mode : mode, perm : int -> std.option(file#))
const close : (f : file# -> bool)
+ const free : (f : file# -> bool)
/* basic i/o. Returns sub-buffer when applicable. */
const write : (f : file#, src : byte[:] -> std.size)
@@ -129,6 +130,14 @@ const sysopen = {path, mode, openmode, perm
/* closes a file, flushing it to the output fd */
const close = {f
+ var closed
+
+ closed = (std.close(f.fd) == 0)
+ free(f)
+ -> closed
+}
+
+const free = {f
flush(f)
if f.mode & Rd != 0
std.slfree(f.rbuf)
@@ -137,7 +146,7 @@ const close = {f
if f.mode & Wr != 0
std.slfree(f.wbuf)
;;
- -> std.close(f.fd) == 0
+ std.free(f)
}
/*