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