Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 8704 → Rev 8705

/programs/develop/libraries/kolibri-libc/source/stdio/fread.c
1,20 → 1,34
#include <stdio.h>
#include <errno.h>
#include "conio.h"
#include "sys/ksys.h"
 
size_t fread(void *restrict ptr, size_t size, size_t nmemb, FILE *restrict stream) {
unsigned bytes_read = 0;
unsigned bytes_count = size * nmemb;
 
for (size_t i = 0; i < bytes_count; i++) {
char c = fgetc(stream);
 
if (c == EOF) {
break;
if(!stream){
errno = EINVAL;
return 0;
}
 
*(char*)(ptr+i) = c;
 
bytes_read++;
if(stream==stdin){
__con_init();
__con_gets((char*)ptr, bytes_count);
return nmemb;
}
 
return bytes_read / size;
else{
if(stream->mode != _STDIO_F_W){
unsigned status = _ksys_file_read_file(stream->name, stream->position, bytes_count, ptr , &bytes_read);
if (status != KSYS_FS_ERR_SUCCESS) {
errno = EIO;
stream->error = errno;
return 0;
}else {
stream->position+=bytes_read;
}
}
}
return bytes_read;
}