Rev 6433 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6433 | Rev 7184 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | #include |
1 | #include |
2 | int fputc(int c,FILE* file) |
2 | int fputc(int c,FILE* file) |
3 | { |
3 | { |
4 | dword res; |
4 | dword res; |
5 | if(!file) |
- | |
6 | { |
- | |
7 | errno = E_INVALIDPTR; |
- | |
8 | return EOF; |
- | |
9 | } |
- | |
Line 10... | Line -... | ||
10 | - | ||
11 | if ((file->mode & 3)==FILE_OPEN_READ) |
- | |
12 | { |
5 | |
13 | errno = E_ACCESS; |
6 | res = fwrite(&c, 1, 1, file); |
14 | return EOF; |
- | |
Line 15... | Line -... | ||
15 | } |
- | |
16 | - | ||
17 | file->buffer[0]=c; |
- | |
18 | if ((file->mode & 3)==FILE_OPEN_APPEND) |
- | |
19 | { |
- | |
20 | file->filepos=file->filesize; |
- | |
21 | file->filesize++; |
- | |
22 | res=_ksys_appendtofile(file->filename,file->filepos,1,file->buffer); |
- | |
23 | if (res!=0) |
- | |
24 | { |
- | |
25 | errno = -res; |
- | |
26 | return EOF; |
- | |
27 | } |
- | |
28 | file->filepos++; |
- | |
29 | return c; |
- | |
30 | } |
- | |
31 | if ((file->mode & 3)==FILE_OPEN_WRITE) |
- | |
32 | { |
- | |
33 | if (file->filepos==0) |
- | |
34 | { //file not created |
- | |
35 | res=_ksys_rewritefile(file->filename,1,file->buffer); |
- | |
36 | if (res!=0) |
- | |
37 | { |
- | |
38 | errno = -res; |
- | |
39 | return EOF; |
- | |
40 | } |
7 | if (res < 1) return EOF; |
41 | file->filepos++; |
8 | |
42 | return c; |
- | |
43 | } |
- | |
44 | else |
- | |
45 | { //file created and need append one byte |
- | |
46 | res=_ksys_appendtofile(file->filename,file->filepos,1,file->buffer); |
- | |
47 | if (res!=0) |
- | |
48 | { |
- | |
49 | errno = -res; |
- | |
50 | return EOF; |
- | |
51 | } |
- | |
52 | file->filepos++; |
- | |
53 | return c; |
- | |
54 | } |
- |