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) {