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
#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
	*/
6433 siemargl 44
	if ((file->mode &3)==FILE_OPEN_WRITE || (file->mode&3)==FILE_OPEN_APPEND) // always true, as read checked previous
647 andrew_pro 45
	{
46
		if (file->filepos==0)
6433 siemargl 47
		{	//file mot created yet
647 andrew_pro 48
			res=_ksys_rewritefile(file->filename,fullsize,buffer);
49
			if (res==0)
50
			{
51
				file->filepos+=fullsize;
52
				fullsize=fullsize/count;
53
				return(fullsize);
6433 siemargl 54
			} else
55
            {
56
                errno = -res;
57
                return(0);
58
            }
647 andrew_pro 59
		}
60
		else
6433 siemargl 61
		{
62
			res=_ksys_appendtofile(file->filename,file->filepos,fullsize,buffer);
647 andrew_pro 63
			if (res==0)
64
			{
65
				file->filepos+=fullsize;
66
				fullsize=fullsize/count;
67
				return(fullsize);
6433 siemargl 68
			} else
69
            {
70
                errno = -res;
71
                return(0);
72
            }
647 andrew_pro 73
		}
74
	}
75
	else return(0);
6433 siemargl 76
}