Fix ungetc EOF having side effects.

This commit is contained in:
Jonas 'Sortie' Termansen 2015-03-15 20:37:28 +01:00
parent 0a63d26bf7
commit 38f8384d78
1 changed files with 3 additions and 6 deletions

View File

@ -29,6 +29,9 @@
extern "C" int ungetc_unlocked(int c, FILE* fp)
{
if ( c == EOF )
return EOF;
if ( !(fp->flags & _FILE_READABLE) )
return errno = EBADF, fp->flags |= _FILE_STATUS_ERROR, EOF;
@ -41,12 +44,6 @@ extern "C" int ungetc_unlocked(int c, FILE* fp)
fp->flags |= _FILE_LAST_READ;
if ( c == EOF )
{
fp->flags &= ~_FILE_STATUS_EOF;
return EOF;
}
// TODO: Is this a bug that ungetc doesn't work for unbuffered files?
if ( fp->buffer_mode == _IONBF )
return errno = EBADF, fp->flags |= _FILE_STATUS_ERROR, EOF;