Subversion Repositories Kolibri OS

Rev

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