forked from KolibriOS/kolibrios
added read buffering, ungetc
git-svn-id: svn://kolibrios.org@7184 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
#include <stdio.h>
|
||||
// non standard realization - no support for virtually change char
|
||||
// non standard realization - support for virtually change ONLY ONE char
|
||||
|
||||
|
||||
|
||||
int ungetc(int c,FILE* file)
|
||||
{
|
||||
dword res;
|
||||
@@ -10,17 +13,19 @@ int ungetc(int c,FILE* file)
|
||||
return EOF;
|
||||
}
|
||||
|
||||
if ((file->mode & 3!=FILE_OPEN_READ) && (file->mode & FILE_OPEN_PLUS==0))
|
||||
if ((file->mode & 3) != FILE_OPEN_READ && (file->mode & FILE_OPEN_PLUS) == 0)
|
||||
{
|
||||
errno = E_ACCESS;
|
||||
return EOF;
|
||||
}
|
||||
|
||||
if (file->filepos>file->filesize || file->filepos==0)
|
||||
if (file->filepos > file->filesize || file->filepos == 0 || c == EOF || file->ungetc_buf != EOF)
|
||||
{
|
||||
errno = E_EOF;
|
||||
return EOF;
|
||||
}
|
||||
|
||||
file->ungetc_buf = c;
|
||||
file->filepos--;
|
||||
|
||||
return c;
|
||||
|
Reference in New Issue
Block a user