diff options
author | Nicholas Noll <nbnoll@eml.cc> | 2021-11-11 14:49:35 -0800 |
---|---|---|
committer | Nicholas Noll <nbnoll@eml.cc> | 2021-11-11 14:49:35 -0800 |
commit | c65794b50b1bc729e7a4e940b76a973afa3030b9 (patch) | |
tree | bc435fea0f3179ac9a4b8de9fdaf993dade9e4ff /sys/libfmt/open.c | |
parent | cc7d219e080263da9813e570436bfd34ab8b1bff (diff) |
feat: libfmt prototype added from plan9
Diffstat (limited to 'sys/libfmt/open.c')
-rw-r--r-- | sys/libfmt/open.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/sys/libfmt/open.c b/sys/libfmt/open.c new file mode 100644 index 0000000..8aadef5 --- /dev/null +++ b/sys/libfmt/open.c @@ -0,0 +1,34 @@ +#include "internal.h" + +static int +flush(fmt·State *io) +{ + int n, fd; + + fd = (uintptr)io->file; + n = io->buffer.cur - io->buffer.beg; + if(n && write(fd, io->buffer.beg, n) != n) + return -1; + + io->buffer.cur = io->buffer.beg; + return io->n; +} + +int +fmt·open(int fd, int len, char *buf, fmt·State *io) +{ + io->buffer.beg = buf; + io->buffer.cur = buf; + io->buffer.end = buf+len; + io->flush = flush; + io->file = (void*)(uintptr)fd; + io->flag = 0; + io->n = 0; + /* no heap needed */ + io->heap = nil; + io->mem = (mem·Reallocator){ 0 }; + + fmt·setlocale(io, nil, nil, nil); + + return 0; +} |