Subversion Repositories Kolibri OS

Rev

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

  1. #include <stdio.h>
  2. #include <errno.h>
  3. #include "conio.h"
  4. #include "sys/ksys.h"
  5.  
  6. size_t fread(void *restrict ptr, size_t size, size_t nmemb, FILE *restrict stream) {
  7.         unsigned bytes_read = 0;
  8.         unsigned bytes_count = size * nmemb;
  9.        
  10.         if(!stream){
  11.                 errno = EINVAL;
  12.                 return 0;
  13.         }
  14.        
  15.         if(stream==stdin){
  16.                 __con_init();
  17.                 __con_gets((char*)ptr, bytes_count);
  18.                 return nmemb;
  19.         }
  20.  
  21.         else{
  22.                 if(stream->mode != _STDIO_F_W){
  23.                         unsigned status = _ksys_file_read_file(stream->name, stream->position, bytes_count, ptr , &bytes_read);
  24.                         if (status != KSYS_FS_ERR_SUCCESS) {
  25.                 errno = EIO;
  26.                 stream->error = errno;
  27.                                 return 0;
  28.                 }else {
  29.                         stream->position+=bytes_read;
  30.                         }
  31.                 }
  32.         }
  33.         return bytes_read;
  34. }
  35.