Subversion Repositories Kolibri OS

Rev

Rev 647 | 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
int fputc(int c,FILE* file)
3
{
4
	dword res;
6433 siemargl 5
    if(!file)
6
    {
7
        errno = E_INVALIDPTR;
8
        return EOF;
9
    }
647 andrew_pro 10
 
6433 siemargl 11
	if ((file->mode & 3)==FILE_OPEN_READ)
12
    {
13
        errno = E_ACCESS;
14
        return EOF;
15
    }
647 andrew_pro 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);
6433 siemargl 23
		if (res!=0)
24
        {
25
            errno = -res;
26
            return EOF;
27
        }
647 andrew_pro 28
		file->filepos++;
6433 siemargl 29
		return c;
647 andrew_pro 30
	}
31
	if ((file->mode & 3)==FILE_OPEN_WRITE)
32
	{
33
		if (file->filepos==0)
6433 siemargl 34
		{	//file not created
647 andrew_pro 35
			res=_ksys_rewritefile(file->filename,1,file->buffer);
6433 siemargl 36
            if (res!=0)
37
            {
38
                errno = -res;
39
                return EOF;
40
            }
647 andrew_pro 41
			file->filepos++;
6433 siemargl 42
			return c;
647 andrew_pro 43
		}
44
		else
6433 siemargl 45
		{	//file created and need append one byte
647 andrew_pro 46
			res=_ksys_appendtofile(file->filename,file->filepos,1,file->buffer);
6433 siemargl 47
            if (res!=0)
48
            {
49
                errno = -res;
50
                return EOF;
51
            }
647 andrew_pro 52
			file->filepos++;
6433 siemargl 53
			return c;
647 andrew_pro 54
		}
55
	}
56
}