From 2e8153019cca5f226e1e7bda17faaa685922aa48 Mon Sep 17 00:00:00 2001 From: Lassi Kortela Date: Tue, 13 Aug 2019 22:53:37 +0300 Subject: [PATCH] Add read-u8 built-in (R7RS) io.getc gets UTF-8 characters --- c/iostream.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/c/iostream.c b/c/iostream.c index 3f201a1..7a20945 100644 --- a/c/iostream.c +++ b/c/iostream.c @@ -153,6 +153,17 @@ value_t fl_read(value_t *args, uint32_t nargs) return v; } +value_t builtin_read_u8(value_t *args, uint32_t nargs) +{ + argcount("read-u8", nargs, 1); + struct ios *s = toiostream(args[0], "read-u8"); + int c; + if ((c = ios_getc(s)) == IOS_EOF) + // lerror(IOError, "io.getc: end of file reached"); + return FL_EOF; + return fixnum(c); +} + value_t fl_iogetc(value_t *args, uint32_t nargs) { argcount("io.getc", nargs, 1); @@ -447,6 +458,7 @@ static struct builtinspec iostreamfunc_info[] = { { "file", fl_file }, { "buffer", fl_buffer }, { "read", fl_read }, + { "read-u8", builtin_read_u8 }, { "write", fl_write }, { "io.flush", fl_ioflush }, { "io.close", fl_ioclose },