forked from KolibriOS/kolibrios
ffca41d7f9
- Added ungetc, tollower and toupper to export - Fixed ungetc emu - Fixed file io functions - Update file_io test git-svn-id: svn://kolibrios.org@8730 a494cfbc-eb01-0410-851d-a64ba20cac60
39 lines
891 B
C
39 lines
891 B
C
#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;
|
|
|
|
if(!stream){
|
|
errno = EBADF;
|
|
return 0;
|
|
}
|
|
|
|
if(stream==stdin){
|
|
__con_init();
|
|
__con_gets((char*)ptr, bytes_count+1);
|
|
return nmemb;
|
|
}
|
|
|
|
else{
|
|
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]);
|
|
}
|
|
unsigned status = _ksys_file_read_file(stream->name, stream->position, bytes_count, ptr , &bytes_read);
|
|
if (status) {
|
|
errno = EIO;
|
|
stream->error = errno;
|
|
return 0;
|
|
}else {
|
|
stream->position+=bytes_read;
|
|
}
|
|
}
|
|
}
|
|
return bytes_read;
|
|
}
|