From 5ee9539e9b2decadd165c12be6159b67093f7cbe Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Thu, 16 Jan 2014 18:42:25 +0900 Subject: [PATCH] impl pic_ungetc --- src/port.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/port.c b/src/port.c index 3a48c940..b943a066 100644 --- a/src/port.c +++ b/src/port.c @@ -165,6 +165,13 @@ pic_fread(void *ptr, size_t block, size_t nitems, pic_file *file) size = block * nitems; /* TODO: optimize block read */ + /* take care of ungetc buf */ + while (file->ur > 0) { + *dst++ = file->ub[--file->ur]; + if (size == 0) + return block * nitems; + } + while (1) { avail = file->c - file->s; if (size <= avail) { @@ -221,6 +228,12 @@ pic_fgetc(pic_file *file) return buf[0]; } +int +pic_ungetc(int c, pic_file *file) +{ + return file->ub[file->ur++] = (char)c; +} + int pic_fputc(int c, pic_file *file) {