Subversion Repositories Kolibri OS

Rev

Rev 8622 | Blame | Last modification | View Log | RSS feed

  1. #include <stdio.h>
  2. #include <errno.h>
  3. #include <ksys.h>
  4.  
  5. int fgetc(FILE* stream)
  6. {
  7.     unsigned bytes_read;
  8.     char c;
  9.  
  10.     unsigned status = _ksys_file_read_file(stream->name, stream->position, 1, &c, &bytes_read);
  11.  
  12.     if (status != _KOS_FS_ERR_SUCCESS) {
  13.         switch (status) {
  14.             case _KOS_FS_ERR_EOF:
  15.                 stream->eof = 1;
  16.                 break;
  17.             case _KOS_FS_ERR_1:
  18.             case _KOS_FS_ERR_2:
  19.             case _KOS_FS_ERR_3:
  20.             case _KOS_FS_ERR_4:
  21.             case _KOS_FS_ERR_5:
  22.             case _KOS_FS_ERR_7:
  23.             case _KOS_FS_ERR_8:
  24.             case _KOS_FS_ERR_9:
  25.             case _KOS_FS_ERR_10:
  26.             case _KOS_FS_ERR_11:
  27.             default:
  28.                 // Just some IO error, who knows what exactly happened
  29.                 errno = EIO;
  30.                 stream->error = errno;
  31.                 break;
  32.         }
  33.         return EOF;
  34.     }
  35.  
  36.     stream->position++;
  37.     return c;
  38. }
  39.