impl pic_ungetc

This commit is contained in:
Yuichi Nishiwaki 2014-01-16 18:42:25 +09:00
parent 4e495c6fcc
commit 5ee9539e9b
1 changed files with 13 additions and 0 deletions

View File

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