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){
|
|
|
|
errno = EINVAL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(stream==stdin){
|
|
|
|
__con_init();
|
|
|
|
__con_gets((char*)ptr, bytes_count);
|
|
|
|
return nmemb;
|
|
|
|
}
|
2021-04-27 18:33:31 +02:00
|
|
|
|
2021-05-01 00:00:07 +02:00
|
|
|
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;
|
|
|
|
}
|
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
|
|
|
}
|