kolibrios/programs/develop/metcc/trunk/libc/file/fread.c
andrew_programmer e5c041df96 Update Kolibri version of libC library(for usage in TinyC).
Correction of various mistakes in functions of work with files.
For work with files 70 function is used.
Functions for work with memory are changed for use of the new manager of memory. 

git-svn-id: svn://kolibrios.org@610 a494cfbc-eb01-0410-851d-a64ba20cac60
2007-08-24 19:49:07 +00:00

25 lines
572 B
C

#include <stdio.h>
#include <mesys.h>
int fread(void *buffer,int size,int count,FILE* file)
{
dword res;
dword fullsize;
if ((file->mode & 3!=FILE_OPEN_READ) && (file->mode & FILE_OPEN_PLUS==0)) return 0;
fullsize=count*size;
if ((fullsize+file->filepos)>(file->filesize))
{
fullsize=file->filesize-file->filepos;
if (fullsize<=0) return(0);
}
res=_ksys_readfile(file->filename,file->filepos,fullsize,buffer);
if (res==0)
{
file->filepos=file->filepos+fullsize;
fullsize=fullsize/size;
return(fullsize);
}
else return 0;
}