Subversion Repositories Kolibri OS

Rev

Rev 6433 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. #include <stdio.h>
  2. int fgetc(FILE* file)
  3. {
  4.         dword res;
  5.     if(!file)
  6.     {
  7.         errno = E_INVALIDPTR;
  8.         return EOF;
  9.     }
  10.  
  11.         if ((file->mode & 3)!=FILE_OPEN_READ && (file->mode & FILE_OPEN_PLUS)==0) return EOF;
  12.  
  13.         if (file->filepos>=file->filesize)
  14.         {
  15.                 return EOF;
  16.         }
  17.         else
  18.         {
  19.                 res=_ksys_readfile(file->filename,file->filepos,1,file->buffer);
  20.                 if (res==0)
  21.                 {
  22.                         file->filepos++;
  23.                         return (int)file->buffer[0];
  24.                 }
  25.                 else
  26.         {
  27.             errno = -res;
  28.             return EOF;  // errors are < 0
  29.         }
  30.         }
  31. }
  32.