ref: a1371465bd9d282020dfecf230917a9e881a5574
parent: 76c13fb5d6c1ba31a4d930e3db5f5466f263f6fb
author: Ori Bernstein <[email protected]>
date: Sun Sep 28 19:30:55 EDT 2014
Allow for destroying a file without closing. This is useful for buffered wrappers around FDs.
--- a/bio.myr
+++ b/bio.myr
@@ -27,6 +27,7 @@
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 @@
/* 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 @@
if f.mode & Wr != 0
std.slfree(f.wbuf)
;;
- -> std.close(f.fd) == 0
+ std.free(f)
}
/*