Subversion Repositories Kolibri OS

Rev

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

  1.  
  2. #include "kolibri.h"
  3. #include <string.h>
  4.  
  5. #include "kolibc.h"
  6.  
  7. int fill_buff(FILE* f);
  8.  
  9. int fread(void* dst,size_t size,size_t count,FILE* f)
  10. { size_t req;
  11.   size_t cnt;
  12.   char *p;
  13. //  if(!((f->mode & FILE_OPEN_READ)|(f->mode & FILE_OPEN_PLUS)))
  14. //                return 0;
  15.   req=count*size;
  16.   p= (char*)dst;
  17.  
  18.   if (req+f->filepos+f->strpos > f->filesize)
  19.                 req=f->filesize-f->filepos-f->strpos;
  20.   count=0;              
  21.   while(req)
  22.   {
  23.     if (f->remain)
  24.     { cnt= (req > f->remain) ? f->remain : req;
  25.       memcpy(p,f->stream,cnt);
  26.       p+=cnt;
  27.       f->stream+=cnt;
  28.       f->strpos+=cnt;
  29.       f->remain-=cnt;
  30.       count+=cnt;
  31.       req-=cnt;
  32.     }
  33.     else
  34.     {
  35.       f->filepos+=8192;
  36.       if(!fill_buff(f))
  37.       { printf("error reading file %d=",f->filepos); //eof or error
  38.         break;
  39.       }
  40.     };    
  41.   };
  42.   return count/size;
  43. }
  44.  
  45. int fill_buff(FILE* f)
  46. { int err;
  47.   size_t bytes;
  48.  
  49.   err=read_file(f->filename,f->buffer,f->filepos,
  50.                              8192,&bytes);
  51.   if(bytes == -1)
  52.     return 0;                          
  53. //  if(!bytes) return 0;
  54.   f->stream = f->buffer;
  55.   f->remain = 8192;
  56.   f->strpos=0;
  57.   return bytes;
  58. };
  59.  
  60.