aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/sys_file.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/runtime/sys_file.c')
-rw-r--r--src/runtime/sys_file.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/src/runtime/sys_file.c b/src/runtime/sys_file.c
index f4d0c98216..70c7fb6521 100644
--- a/src/runtime/sys_file.c
+++ b/src/runtime/sys_file.c
@@ -37,12 +37,39 @@ sys·readfile(string filein, string fileout, bool okout)
fileout = nil;
goto close_out;
}
- okout = 1;
+ okout = true;
close_out:
close(fd);
out:
FLUSH(&fileout);
FLUSH(&okout);
- return;
+}
+
+void
+sys·writefile(string filein, string textin, bool okout)
+{
+ int32 fd;
+ byte namebuf[256];
+
+ okout = false;
+
+ if(filein == nil || filein->len >= sizeof(namebuf))
+ goto out;
+
+ mcpy(namebuf, filein->str, filein->len);
+ namebuf[filein->len] = '\0';
+ fd = open(namebuf, 1|0x0200, 0644); // open for write, create if non-existant (sic)
+ if(fd < 0)
+ goto out;
+
+ if (write(fd, textin->str, textin->len) != textin->len) {
+ goto close_out;
+ }
+ okout = true;
+
+close_out:
+ close(fd);
+out:
+ FLUSH(&okout);
}