From 4fbf50ddfeeb0e9d99d271e31dd35d545fb42ab6 Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Tue, 21 Apr 2020 10:40:03 -0700 Subject: feat: added wrapper for io --- include/libn.h | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'include') 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 #include +#include #include #include -#include // ---------------------------------------------------------------------------- // 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" // ----------------------------------------------------------------------------- @@ -66,6 +67,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. -- cgit v1.2.1