Rev 8687 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 8687 | Rev 8705 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | #include |
1 | #include |
- | 2 | #include |
|
- | 3 | #include "conio.h" |
|
- | 4 | #include "sys/ksys.h" |
|
Line 2... | Line 5... | ||
2 | 5 | ||
3 | size_t fread(void *restrict ptr, size_t size, size_t nmemb, FILE *restrict stream) { |
6 | size_t fread(void *restrict ptr, size_t size, size_t nmemb, FILE *restrict stream) { |
4 | unsigned bytes_read = 0; |
7 | unsigned bytes_read = 0; |
Line 5... | Line -... | ||
5 | unsigned bytes_count = size * nmemb; |
- | |
6 | 8 | unsigned bytes_count = size * nmemb; |
|
7 | for (size_t i = 0; i < bytes_count; i++) { |
- | |
8 | char c = fgetc(stream); |
9 | |
9 | 10 | if(!stream){ |
|
10 | if (c == EOF) { |
11 | errno = EINVAL; |
Line -... | Line 12... | ||
- | 12 | return 0; |
|
11 | break; |
13 | } |
12 | } |
- | |
- | 14 | ||
13 | 15 | if(stream==stdin){ |
|
14 | *(char*)(ptr+i) = c; |
16 | __con_init(); |
Line -... | Line 17... | ||
- | 17 | __con_gets((char*)ptr, bytes_count); |
|
- | 18 | return nmemb; |
|
- | 19 | } |
|
- | 20 | ||
- | 21 | else{ |
|
- | 22 | if(stream->mode != _STDIO_F_W){ |
|
- | 23 | unsigned status = _ksys_file_read_file(stream->name, stream->position, bytes_count, ptr , &bytes_read); |
|
- | 24 | if (status != KSYS_FS_ERR_SUCCESS) { |
|
- | 25 | errno = EIO; |
|
- | 26 | stream->error = errno; |
|
- | 27 | return 0; |
|
- | 28 | }else { |
|
15 | 29 | stream->position+=bytes_read; |
|
16 | bytes_read++; |
30 | } |