Subversion Repositories Kolibri OS

Rev

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

  1. #include <stdio.h>
  2. #include <kolibrisys.h>
  3.  
  4. int fread(void *buffer,int size,int count,FILE* file)
  5. {
  6.         dword res;
  7.         dword fullsize;
  8.  
  9.     if(!file || !buffer)
  10.     {
  11.         errno = E_INVALIDPTR;
  12.         return 0;
  13.     }
  14.  
  15.         if ((file->mode &3)!=FILE_OPEN_READ && (file->mode & FILE_OPEN_PLUS==0))
  16.     {
  17.         errno = E_ACCESS;
  18.         return 0;
  19.     }
  20.  
  21.         fullsize=count*size;
  22.         if ((fullsize+file->filepos)>=(file->filesize))
  23.         {
  24.                 fullsize=file->filesize-file->filepos;
  25.                 if (fullsize<=0) return(0);
  26.         }
  27.  
  28.         res=_ksys_readfile(file->filename,file->filepos,fullsize,buffer);
  29.         if (res==0)
  30.         {
  31.                 file->filepos=file->filepos+fullsize;
  32.                 fullsize=fullsize/size;
  33.                 return(fullsize);
  34.         }
  35.         else
  36.     {
  37.         errno = -res;
  38.         return 0;
  39.     }
  40. }
  41.