impl pic_ungetc
This commit is contained in:
parent
4e495c6fcc
commit
5ee9539e9b
13
src/port.c
13
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 */
|
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) {
|
while (1) {
|
||||||
avail = file->c - file->s;
|
avail = file->c - file->s;
|
||||||
if (size <= avail) {
|
if (size <= avail) {
|
||||||
|
@ -221,6 +228,12 @@ pic_fgetc(pic_file *file)
|
||||||
return buf[0];
|
return buf[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
pic_ungetc(int c, pic_file *file)
|
||||||
|
{
|
||||||
|
return file->ub[file->ur++] = (char)c;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
pic_fputc(int c, pic_file *file)
|
pic_fputc(int c, pic_file *file)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue