2021-04-27 18:33:31 +02:00
|
|
|
#include <stdio.h>
|
2021-05-01 00:00:07 +02:00
|
|
|
#include <errno.h>
|
|
|
|
#include "conio.h"
|
|
|
|
#include "sys/ksys.h"
|
2021-04-27 18:33:31 +02:00
|
|
|
|
|
|
|
size_t fread(void *restrict ptr, size_t size, size_t nmemb, FILE *restrict stream) {
|
|
|
|
unsigned bytes_read = 0;
|
|
|
|
unsigned bytes_count = size * nmemb;
|
2021-05-01 00:00:07 +02:00
|
|
|
|
|
|
|
if(!stream){
|
2021-05-23 17:28:07 +02:00
|
|
|
errno = EBADF;
|
2021-05-01 00:00:07 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(stream==stdin){
|
|
|
|
__con_init();
|
2021-05-23 17:28:07 +02:00
|
|
|
__con_gets((char*)ptr, bytes_count+1);
|
2021-05-01 00:00:07 +02:00
|
|
|
return nmemb;
|
|
|
|
}
|
2021-04-27 18:33:31 +02:00
|
|
|
|
2021-05-01 00:00:07 +02:00
|
|
|
else{
|
2021-05-23 17:28:07 +02:00
|
|
|
if(stream->mode & _FILEMODE_R){
|
|
|
|
if(!stream->__ungetc_emu_buff){
|
|
|
|
((char*) ptr)[0]=(char)stream->__ungetc_emu_buff;
|
|
|
|
//debug_printf("Ungetc: %x\n", ((char*) ptr)[0]);
|
|
|
|
}
|
2021-05-01 00:00:07 +02:00
|
|
|
unsigned status = _ksys_file_read_file(stream->name, stream->position, bytes_count, ptr , &bytes_read);
|
2021-05-23 17:28:07 +02:00
|
|
|
if (status) {
|
2021-05-01 00:00:07 +02:00
|
|
|
errno = EIO;
|
|
|
|
stream->error = errno;
|
|
|
|
return 0;
|
|
|
|
}else {
|
|
|
|
stream->position+=bytes_read;
|
|
|
|
}
|
2021-04-27 18:33:31 +02:00
|
|
|
}
|
|
|
|
}
|
2021-05-01 00:00:07 +02:00
|
|
|
return bytes_read;
|
2021-04-27 18:33:31 +02:00
|
|
|
}
|