2021-05-10 00:12:43 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
// non standard realization - support for virtually change ONLY ONE char
|
|
|
|
|
|
|
|
int ungetc(int c, FILE* file)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
|
|
|
|
if(!file){
|
|
|
|
errno = EBADF;
|
|
|
|
return EOF;
|
|
|
|
}
|
|
|
|
|
2021-05-23 17:28:07 +02:00
|
|
|
if (file->mode != _FILEMODE_R){
|
2021-05-10 00:12:43 +02:00
|
|
|
errno = EACCES;
|
|
|
|
return EOF;
|
|
|
|
}
|
|
|
|
|
2021-05-23 17:28:07 +02:00
|
|
|
if (file->position == 0 || c == EOF)
|
2021-05-10 00:12:43 +02:00
|
|
|
{
|
|
|
|
errno = EOF;
|
|
|
|
return EOF;
|
|
|
|
}
|
|
|
|
|
|
|
|
file->__ungetc_emu_buff = c;
|
|
|
|
file->position--;
|
|
|
|
return c;
|
|
|
|
}
|