2007-08-24 21:49:07 +02:00
|
|
|
#include <stdio.h>
|
2006-09-07 16:14:53 +02:00
|
|
|
int fgetc(FILE* file)
|
|
|
|
{
|
2007-08-24 21:49:07 +02:00
|
|
|
dword res;
|
2016-05-19 14:15:22 +02:00
|
|
|
if(!file)
|
|
|
|
{
|
|
|
|
errno = E_INVALIDPTR;
|
|
|
|
return EOF;
|
|
|
|
}
|
2007-08-24 21:49:07 +02:00
|
|
|
|
2018-03-05 18:53:31 +01:00
|
|
|
if ((file->mode & 3)!=FILE_OPEN_READ && (file->mode & FILE_OPEN_PLUS)==0) return EOF;
|
2007-08-24 21:49:07 +02:00
|
|
|
|
2006-09-07 16:14:53 +02:00
|
|
|
if (file->filepos>=file->filesize)
|
2007-08-24 21:49:07 +02:00
|
|
|
{
|
|
|
|
return EOF;
|
|
|
|
}
|
2006-09-07 16:14:53 +02:00
|
|
|
else
|
|
|
|
{
|
2007-08-24 21:49:07 +02:00
|
|
|
res=_ksys_readfile(file->filename,file->filepos,1,file->buffer);
|
|
|
|
if (res==0)
|
|
|
|
{
|
|
|
|
file->filepos++;
|
|
|
|
return (int)file->buffer[0];
|
|
|
|
}
|
2016-05-19 14:15:22 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
errno = -res;
|
|
|
|
return EOF; // errors are < 0
|
|
|
|
}
|
2006-09-07 16:14:53 +02:00
|
|
|
}
|
2016-05-19 14:15:22 +02:00
|
|
|
}
|