summaryrefslogtreecommitdiff
path: root/libstd/blat.myr
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2013-06-05 15:30:30 -0400
committerOri Bernstein <ori@eigenstate.org>2013-06-05 15:30:30 -0400
commiteffa98dac67fd796ef9414afef330722657e45cb (patch)
tree68b44799dd885b2cee72d62b10eddb766ac029c4 /libstd/blat.myr
parent3aac04fb7bef769b7d3fc6389c7dd76ea196fdc0 (diff)
downloadmc-effa98dac67fd796ef9414afef330722657e45cb.tar.gz
Add code for a 'blat()' function.
Diffstat (limited to 'libstd/blat.myr')
-rw-r--r--libstd/blat.myr28
1 files changed, 28 insertions, 0 deletions
diff --git a/libstd/blat.myr b/libstd/blat.myr
new file mode 100644
index 0000000..f5a665e
--- /dev/null
+++ b/libstd/blat.myr
@@ -0,0 +1,28 @@
+use "sys.use"
+use "fmt.use"
+
+pkg std =
+ const blat : (path : byte[:], buf : byte[:] -> bool)
+;;
+
+const blat = {path, buf
+ var fd
+ var written
+ var n
+
+ fd = open(path, Ocreat|Owronly, 0o777)
+ if fd < 0
+ fatal(1, "Could not open file \"%s\"", path)
+ ;;
+
+ n = 0
+ while true
+ written = write(fd, buf[n:])
+ if written <= 0
+ goto done
+ ;;
+ n += written
+ ;;
+:done
+ -> written == 0
+}