summaryrefslogtreecommitdiff
path: root/lib/std/blat.myr
diff options
context:
space:
mode:
Diffstat (limited to 'lib/std/blat.myr')
-rw-r--r--lib/std/blat.myr32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/std/blat.myr b/lib/std/blat.myr
new file mode 100644
index 0000000..90c0f94
--- /dev/null
+++ b/lib/std/blat.myr
@@ -0,0 +1,32 @@
+use "syswrap.use"
+
+pkg std =
+ const blat : (path : byte[:], buf : byte[:], perm : int64 -> bool)
+ const fblat : (f : fd, buf : byte[:] -> bool)
+;;
+
+const blat = {path, buf, perm
+ var fd
+
+ fd = openmode(path, Ocreat|Owronly, perm)
+ if fd < 0
+ -> false
+ ;;
+ -> fblat(fd, buf)
+}
+
+
+const fblat = {fd, buf
+ var written, n
+
+ n = 0
+ while true
+ written = write(fd, buf[n:])
+ if written <= 0
+ goto done
+ ;;
+ n += written
+ ;;
+:done
+ -> written == 0 && n == buf.len
+}