aboutsummaryrefslogtreecommitdiff
path: root/include
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 /include
parent82885d35ea1b52982ebcf3a58e9d328cfa4e933a (diff)
feat: added wrapper for io
Diffstat (limited to 'include')
-rw-r--r--include/libn.h35
1 files changed, 30 insertions, 5 deletions
diff --git a/include/libn.h b/include/libn.h
index aad359e..64e2e70 100644
--- a/include/libn.h
+++ b/include/libn.h
@@ -11,9 +11,9 @@
#include <stdio.h>
#include <unistd.h>
+#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
-#include <fcntl.h>
// ----------------------------------------------------------------------------
// Dynamic array.
@@ -50,15 +50,16 @@ void _bufpop(void*, int, vlong);
// -----------------------------------------------------------------------------
// Co-routines
-typedef struct coro coro;
+typedef struct Coro Coro;
-coro* coro·new(uintptr stk, uintptr (*func)(coro*, uintptr));
-uintptr coro·yield(coro *c, uintptr arg);
-error coro·free(coro *c);
+Coro* coro·new(uintptr stk, uintptr (*func)(Coro*, uintptr));
+uintptr coro·yield(Coro *c, uintptr arg);
+error coro·free(Coro *c);
// -----------------------------------------------------------------------------
// Strings
+// TODO(nnoll): Move here?
#include ".include/str.h"
// -----------------------------------------------------------------------------
@@ -67,6 +68,30 @@ error coro·free(coro *c);
#include ".include/map.h"
// -----------------------------------------------------------------------------
+// I/O
+
+typedef FILE Stream;
+enum SeekPos
+{
+ seek·CUR = SEEK_CUR,
+ seek·SET = SEEK_SET,
+ seek·END = SEEK_END
+};
+
+Stream *io·open(byte *name, byte *mode);
+error io·close(Stream *s);
+byte io·getbyte(Stream *s);
+vlong io·read(Stream *s, int sz, int n, void *buf);
+int io·readln(Stream *s, int n, byte* buf);
+error io·putbyte(Stream *s, byte c);
+int io·putstring(Stream *s, string str);
+vlong io·write(Stream *s, int sz, int n, void *buf);
+int io·seek(Stream *s, long off, enum SeekPos origin);
+
+// -----------------------------------------------------------------------------
+// Buffered I/O
+
+// -----------------------------------------------------------------------------
// Error handling functions.
void errorf(const byte* fmt, ...);