From 5bcc08d92ae9345d6863f555a3dd9ec960e0860f Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Thu, 18 Nov 2021 16:40:51 -0800 Subject: feat: filling out system layer's interface --- include/base.h | 80 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 42 insertions(+), 38 deletions(-) (limited to 'include/base.h') diff --git a/include/base.h b/include/base.h index 7077731..df580c3 100644 --- a/include/base.h +++ b/include/base.h @@ -3,8 +3,10 @@ // ------------------------------------------------------------------------ // standard library -//#include -// +#include +#include + +// TODO: remove dependency system headers #include #include #include @@ -125,9 +127,6 @@ char *str·copyn(char *dst, char *src, int n); // ----------------------------------------------------------------------------- // i/o -typedef FILE io·Stream; -typedef struct stat io·Stat; - enum SeekPos { seek·cur = SEEK_CUR, @@ -135,37 +134,6 @@ enum SeekPos seek·end = SEEK_END }; -/* XXX: change casing */ -enum -{ - ReadOK = R_OK, - WriteOK = W_OK, - ExecOK = X_OK, -}; - -/* file handling */ -io·Stream *io·open(byte *name, byte *mode); -int io·fd(io·Stream *s); -int io·stat(io·Stream *s, io·Stat *buf); -int io·close(io·Stream *s); -byte io·getbyte(io·Stream *s); -int io·ungetbyte(io·Stream *s, byte c); -int io·read(io·Stream *s, int sz, int n, void *buf); -int io·readln(io·Stream *s, int n, byte *buf); -int io·putbyte(io·Stream *s, byte c); -int io·putstring(io·Stream *s, string str); -int io·write(io·Stream *s, int sz, int n, void *buf); -int io·flush(io·Stream *s); -int io·seek(io·Stream *s, long off, enum SeekPos whence); -long io·tell(io·Stream *s); - -/* basic os helpers */ -int os·exists(byte *path, int flag); -byte *os·dirname(byte *path); -byte *os·basename(byte *path); -int os·sep(void); - -/* io interfaces */ typedef struct io·Reader { int (*read)(void*, int sz, int n, void *buf); @@ -227,6 +195,42 @@ typedef struct io·ReadWriter } io·ReadWriter; extern io·ReadWriter sys·ReadWriter; +/* XXX: change casing */ +enum +{ + ReadOK = R_OK, + WriteOK = W_OK, + ExecOK = X_OK, +}; + +/* XXX(deprecated): file handling */ + +typedef FILE io·Stream; +typedef struct stat io·Stat; + +io·Stream *io·open(byte *name, byte *mode); +int io·fd(io·Stream *s); +int io·stat(io·Stream *s, io·Stat *buf); +int io·close(io·Stream *s); +byte io·getbyte(io·Stream *s); +int io·ungetbyte(io·Stream *s, byte c); +int io·read(io·Stream *s, int sz, int n, void *buf); +int io·readln(io·Stream *s, int n, byte *buf); +int io·putbyte(io·Stream *s, byte c); +int io·putstring(io·Stream *s, string str); +int io·write(io·Stream *s, int sz, int n, void *buf); +int io·flush(io·Stream *s); +int io·seek(io·Stream *s, long off, enum SeekPos whence); +long io·tell(io·Stream *s); + +/* basic os helpers */ + +int os·exists(byte *path, int flag); +byte *os·dirname(byte *path); +byte *os·basename(byte *path); +int os·sep(void); + +/* io interfaces */ /* buffered i/o */ typedef struct io·Buffer io·Buffer; @@ -364,9 +368,9 @@ long gz·tell(gz·Stream *s); void exits(char *s); void errorf(byte* fmt, ...); -void verrorf(byte* fmt, va_list args); +void verrorf(byte* fmt, va_list args); void panicf(byte *fmt, ...); -void vpanicf(byte *fmt, va_list args); +void vpanicf(byte *fmt, va_list args); // ----------------------------------------------------------------------------- // sorting -- cgit v1.2.1