Rev 7184 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
647 | andrew_pro | 1 | #include |
2 | #include |
||
3 | |||
7418 | siemargl | 4 | // dont support return partial writing when fail |
5 | // only 32-bit filesize |
||
647 | andrew_pro | 6 | int fwrite(void *buffer,int size,int count,FILE* file) |
7 | { |
||
8 | dword res; |
||
9 | dword fullsize; |
||
10 | |||
6433 | siemargl | 11 | if(!file || !buffer) |
12 | { |
||
13 | errno = E_INVALIDPTR; |
||
14 | return EOF; |
||
15 | } |
||
647 | andrew_pro | 16 | |
6433 | siemargl | 17 | |
18 | if ((file->mode & 3)==FILE_OPEN_READ) |
||
19 | { |
||
20 | errno = E_ACCESS; |
||
21 | return 0; |
||
22 | } |
||
23 | |||
24 | if ((file->mode &3)==FILE_OPEN_APPEND) |
||
647 | andrew_pro | 25 | file->filepos=file->filesize; |
6433 | siemargl | 26 | |
27 | fullsize=count*size; |
||
28 | |||
647 | andrew_pro | 29 | if ((file->filesize)<(file->filepos+fullsize)) file->filesize=file->filepos+fullsize; |
30 | |||
31 | /* |
||
32 | if (file->mode==FILE_OPEN_APPEND) |
||
33 | { |
||
34 | file->filepos==file->filesize; |
||
35 | res=_ksys_appendtofile(file->filename,file->filepos,fullsize,buffer); |
||
36 | if (res==0) |
||
37 | { |
||
38 | file->filepos+=fullsize; |
||
39 | fullsize=fullsize/size; |
||
40 | return(fullsize); |
||
41 | } |
||
42 | else return(0); |
||
6433 | siemargl | 43 | |
647 | andrew_pro | 44 | } |
45 | */ |
||
7184 | siemargl | 46 | file->ungetc_buf = EOF; |
47 | if (file->filepos >= file->buffer_start && file->filepos < file->buffer_end) // drop buffer, if change his data |
||
48 | { |
||
49 | file->buffer_start = -1; |
||
50 | file->buffer_end = -1; |
||
51 | } |
||
52 | |||
6433 | siemargl | 53 | if ((file->mode &3)==FILE_OPEN_WRITE || (file->mode&3)==FILE_OPEN_APPEND) // always true, as read checked previous |
647 | andrew_pro | 54 | { |
55 | if (file->filepos==0) |
||
6433 | siemargl | 56 | { //file mot created yet |
647 | andrew_pro | 57 | res=_ksys_rewritefile(file->filename,fullsize,buffer); |
58 | if (res==0) |
||
59 | { |
||
60 | file->filepos+=fullsize; |
||
7418 | siemargl | 61 | return(count); |
6433 | siemargl | 62 | } else |
63 | { |
||
64 | errno = -res; |
||
65 | return(0); |
||
66 | } |
||
647 | andrew_pro | 67 | } |
68 | else |
||
6433 | siemargl | 69 | { |
70 | res=_ksys_appendtofile(file->filename,file->filepos,fullsize,buffer); |
||
647 | andrew_pro | 71 | if (res==0) |
72 | { |
||
73 | file->filepos+=fullsize; |
||
7418 | siemargl | 74 | return(count); |
6433 | siemargl | 75 | } else |
76 | { |
||
77 | errno = -res; |
||
78 | return(0); |
||
79 | } |
||
647 | andrew_pro | 80 | } |
81 | } |
||
82 | else return(0); |
||
6433 | siemargl | 83 | }>(file-> |