aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorNicholas <nbnoll@eml.cc>2021-11-20 11:55:55 -0800
committerNicholas <nbnoll@eml.cc>2021-11-20 12:34:01 -0800
commite97c8c469db0aa27985dab2879dc1f14905c7387 (patch)
treef10f7ed68f1ad5212eebb0985ef040c5e96235ba /include
parenta9bfe650038afea8b751175cac16f6027345e45f (diff)
chore: simplify makefiles
Diffstat (limited to 'include')
-rw-r--r--include/base.h1
-rw-r--r--include/base/io.h64
2 files changed, 33 insertions, 32 deletions
diff --git a/include/base.h b/include/base.h
index 8152cb7..a7e9319 100644
--- a/include/base.h
+++ b/include/base.h
@@ -29,6 +29,7 @@ typedef wchar_t wchar;
#include <base/error.h>
#include <base/io.h>
+/* no dependencies */
#include <base/fmt.h>
#include <base/utf.h>
#include <base/coro.h>
diff --git a/include/base/io.h b/include/base/io.h
index f8c0bcc..5e0f1e0 100644
--- a/include/base/io.h
+++ b/include/base/io.h
@@ -96,46 +96,46 @@ 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;
+#define iota(x) (1 << (x))
enum
{
- bufio·size = 2*4096,
- bufio·ungets = 8,
- bufio·eof = -1,
- bufio·err = -2,
-
- bufio·nil = 1 << 0,
- bufio·rdr = 1 << 1,
- bufio·wtr = 1 << 2,
- bufio·end = 1 << 3,
+ io·BufEof = -1,
+ io·BufErr = -2,
+ io·BufUngets = 8,
+ io·BufMagic = 0x314159,
+ io·BufLen = 2*4096,
+
+ /* state */
+ io·BufNil = iota(0),
+ io·BufRdr = iota(1),
+ io·BufWtr = iota(2),
+ io·BufEnd = iota(3)
};
+#undef iota
struct io·Buffer
{
- int state;
- int runesize;
- void *h;
- union {
- io·Reader rdr;
- io·Writer wtr;
- };
- vlong size;
- byte *beg, *pos, *end;
- byte buf[bufio·size + bufio·ungets];
+ int state, id, flag;
+ struct{
+ int in; /* negative number of bytes at end */
+ int out; /* number of bytes at start */
+ int line; /* number of bytes after last readline */
+ } off;
+ intptr pos, cap; /* position in file, capacity of buffer */
+ uchar *b,*g,*e; /* start, good bytes, end of byte pointers */
+ uchar bytes[];
};
-int bufio·initreader(io·Buffer *buf, io·Reader rdr, void *h);
-void bufio·finireader(io·Buffer *buf);
-int bufio·getbyte(io·Buffer *buf);
-int bufio·ungetbyte(io·Buffer *buf, byte c);
-int bufio·read(io·Buffer *buf, int sz, int n, void *out);
+int bio·init(io·Buffer *io, int fd, int mode);
+int bio·initcap(io·Buffer *io, int fd, int mode, int cap);
+
+/* basic os helpers */
+/* XXX: find a better location for this */
+int os·exists(byte *path, int flag);
+byte *os·dirname(byte *path);
+byte *os·basename(byte *path);
+int os·sep(void);
+