aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2020-04-18 13:40:53 -0700
committerNicholas Noll <nbnoll@eml.cc>2020-04-18 13:40:53 -0700
commit21055a1e5d34dda1b8151dd46a6bedca22bd73d9 (patch)
tree721044b20eb1c6f00d63a70f59a07f8b40e45ee1 /include
parent392c9aff947a41e7e0da0b1a9612e174cfa956a7 (diff)
feat: added prototype of io/buffered io
Diffstat (limited to 'include')
-rw-r--r--include/bufio.h27
-rw-r--r--include/io.h34
2 files changed, 61 insertions, 0 deletions
diff --git a/include/bufio.h b/include/bufio.h
new file mode 100644
index 0000000..b672563
--- /dev/null
+++ b/include/bufio.h
@@ -0,0 +1,27 @@
+#pragma once
+
+typedef struct bufio·Reader bufio·Reader;
+
+bufio·Reader *bufio·newreader(io·Reader r);
+error bufio·freereader(bufio·Reader *r);
+
+int bufio·read(bufio·Reader *r, byte *buf, int n);
+int bufio·readln(bufio·Reader *r, byte *buf, int n, error* err);
+byte bufio·get(bufio·Reader *r);
+error bufio·unget(bufio·Reader *r);
+byte bufio·peek(bufio·Reader *r);
+int bufio·peekfor(bufio·Reader *r, byte *buf, int n);
+void bufio·discard(bufio·Reader *r, int n);
+void bufio·clear(bufio·Reader *r);
+
+typedef struct bufio·Writer bufio·Writer;
+
+bufio·Writer *bufio·newwriter(io·Writer w);
+error bufio·freewriter(bufio·Writer *w);
+
+int bufio·write(bufio·Writer *w, byte *buf, int n);
+error bufio·put(bufio·Writer *w, byte b);
+error bufio·flush(bufio·Writer* w);
+
+/* TODO */
+typedef struct bufio·Scanner bufio·Scanner;
diff --git a/include/io.h b/include/io.h
new file mode 100644
index 0000000..9813b85
--- /dev/null
+++ b/include/io.h
@@ -0,0 +1,34 @@
+#pragma once
+
+typedef struct io·Reader
+{
+ Iface impl;
+ int (*read)(void*, byte *buf, int n);
+} io·Reader;
+
+typedef struct io·ByteReader
+{
+ Iface impl;
+ int (*read)(void*, byte *buf, int n);
+ byte (*get)(void*);
+} io·ByteReader;
+
+typedef struct io·Writer
+{
+ Iface impl;
+ int (*write)(void*, byte *buf, int n);
+} io·Writer;
+
+typedef struct io·ReadWriter
+{
+ Iface impl;
+ int (*read)(void*, byte *buf, int n);
+ int (*write)(void*, byte *buf, int n);
+} io·ReadWriter;
+
+typedef enum io·SeekPos
+{
+ SEEK·set,
+ SEEK·cur,
+ SEEK·end,
+} io·SeekPos;