Rev 8687 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
8687 | turbocat | 1 | #include |
2 | #include "conio.h" |
||
3 | #include |
||
4 | #include |
||
5 | |||
6 | |||
7 | size_t fwrite(const void *restrict ptr, size_t size, size_t nmemb, FILE *restrict stream) { |
||
8 | unsigned bytes_written = 0; |
||
9 | unsigned bytes_count = size * nmemb; |
||
10 | |||
11 | if(!stream){ |
||
8730 | turbocat | 12 | errno = EBADF; |
8687 | turbocat | 13 | return 0; |
14 | } |
||
15 | |||
16 | if(stream==stdout){ |
||
17 | __con_init(); |
||
18 | __con_write_string((char*)ptr, bytes_count); |
||
19 | return nmemb; |
||
20 | } |
||
21 | else if(stream==stderr){ |
||
22 | for (size_t i = 0; i < bytes_count; i++) { |
||
23 | char c = *(char*)(ptr+i); |
||
24 | _ksys_debug_putc(c); |
||
25 | } |
||
26 | } |
||
27 | else{ |
||
8730 | turbocat | 28 | if(stream->mode != _FILEMODE_R){ |
8687 | turbocat | 29 | unsigned status = _ksys_file_write_file(stream->name, stream->position, bytes_count, ptr, &bytes_written); |
30 | if (status != KSYS_FS_ERR_SUCCESS) { |
||
31 | errno = EIO; |
||
32 | stream->error = errno; |
||
33 | return 0; |
||
34 | }else { |
||
35 | stream->position+=bytes_written; |
||
36 | } |
||
37 | } |
||
38 | } |
||
39 | return bytes_written; |
||
40 | }> |