1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

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

View file

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