aboutsummaryrefslogtreecommitdiff
path: root/sys/libn/io.c
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2020-04-21 10:40:03 -0700
committerNicholas Noll <nbnoll@eml.cc>2020-04-21 10:40:03 -0700
commit4fbf50ddfeeb0e9d99d271e31dd35d545fb42ab6 (patch)
tree2a9664a6c9d8aa57102bbe40a306fddf3d86ff2b /sys/libn/io.c
parent82885d35ea1b52982ebcf3a58e9d328cfa4e933a (diff)
feat: added wrapper for io
Diffstat (limited to 'sys/libn/io.c')
-rw-r--r--sys/libn/io.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/sys/libn/io.c b/sys/libn/io.c
new file mode 100644
index 0000000..789bc7b
--- /dev/null
+++ b/sys/libn/io.c
@@ -0,0 +1,71 @@
+#include <u.h>
+#include <libn.h>
+
+// -----------------------------------------------------------------------
+// Open/Close
+
+Stream*
+io·open(byte *name, byte *mode)
+{
+ return fopen(name, mode);
+}
+
+error
+io·close(Stream *s)
+{
+ return fclose(s);
+}
+
+// -----------------------------------------------------------------------
+// Reading
+
+byte
+io·getbyte(Stream *s)
+{
+ return fgetc(s);
+}
+
+vlong
+io·read(Stream *s, int sz, int n, void *buf)
+{
+ return fread(buf, sz, n, s);
+}
+
+int
+io·readln(Stream *s, int n, byte* buf)
+{
+ byte* b;
+ b = fgets(buf, n+1, s);
+
+ return strlen(buf);
+}
+
+// -----------------------------------------------------------------------
+// Writing
+
+error
+io·putbyte(Stream *s, byte c)
+{
+ return fputc(c, s);
+}
+
+int
+io·putstring(Stream *s, string str)
+{
+ return fputs(str, s);
+}
+
+vlong
+io·write(Stream *s, int sz, int n, void *buf)
+{
+ return fwrite(buf, sz, n, s);
+}
+
+// -----------------------------------------------------------------------
+// Seek
+
+int
+io·seek(Stream *s, long off, enum SeekPos origin)
+{
+ return fseek(s, off, origin);
+}