home *** CD-ROM | disk | FTP | other *** search
/ EuroCD 3 / EuroCD 3.iso / Programming / vbcc / machines / amiga68k / libsrc / stdio / fread.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-24  |  824 b   |  34 lines

  1. #include <stdio.h>
  2.  
  3. #include <proto/dos.h>
  4.  
  5. size_t fread(void *ptr,size_t size,size_t nmemb,FILE *f)
  6. {
  7.     size_t cnt,total=size*nmemb;
  8.     char *p=ptr;
  9.     long result;
  10.     if(!f||!total) return(0);
  11.     if((f->flags&(_READABLE|_WRITE|_ERR|_EOF))!=_READABLE) return(0);
  12.     f->flags|=_READ;
  13.     if(cnt=f->count){
  14.     /*  Buffer lesen    */
  15.         if(total<=cnt){
  16.             memcpy(p,f->pointer,total);
  17.             f->pointer+=total;f->count-=total;
  18.             return(nmemb);
  19.         }else{
  20.             memcpy(p,f->pointer,cnt);
  21.             total-=cnt;p+=cnt;
  22.             f->count=0;
  23.         }
  24.     }
  25.     result=Read((BPTR)f->filehandle,p,total);
  26.     if(result==-1){f->flags|=_ERR;return(cnt/size);}
  27.     if(result<total){
  28.         f->flags|=_EOF;
  29.         return((cnt+result)/size);
  30.     }else{
  31.         return(nmemb);
  32.     }
  33. }
  34.