From d79a16a7d172ece3b01bf78ab7c6db02dc9cf267 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sun, 31 Mar 2024 17:22:46 +0200 Subject: Add mbio.h and freadrune() --- lib/mbio/freadrune.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 lib/mbio/freadrune.c (limited to 'lib/mbio') diff --git a/lib/mbio/freadrune.c b/lib/mbio/freadrune.c new file mode 100644 index 0000000..efa42b3 --- /dev/null +++ b/lib/mbio/freadrune.c @@ -0,0 +1,23 @@ +#include +#include +#include + +#include "mbio.h" +#include "mbstring.h" + +int +freadrune(rune *ch, u8_io_state *st, FILE *stream) +{ + size_t n, need; + need = lengthof(st->_buf) - st->_fill; + st->_fill += n = fread(st->_buf + st->_fill, 1, need, stream); + if (n < need && ferror(stream)) + return -1; + if (st->_fill == 0) + return 0; + + int w = u8tor(ch, st->_buf); + memmove(st->_buf, st->_buf + w, lengthof(st->_buf) - w); + st->_fill -= w; + return w; +} -- cgit v1.2.3