2007-08-24 21:49:07 +02:00
|
|
|
#include <stdio.h>
|
2007-10-15 11:42:17 +02:00
|
|
|
#include <kolibrisys.h>
|
2007-08-24 21:49:07 +02:00
|
|
|
|
|
|
|
int fwrite(void *buffer,int size,int count,FILE* file)
|
2006-09-07 16:14:53 +02:00
|
|
|
{
|
2007-08-24 21:49:07 +02:00
|
|
|
dword res;
|
|
|
|
dword fullsize;
|
|
|
|
|
2016-05-19 14:15:22 +02:00
|
|
|
if(!file || !buffer)
|
|
|
|
{
|
|
|
|
errno = E_INVALIDPTR;
|
|
|
|
return EOF;
|
|
|
|
}
|
2007-08-24 21:49:07 +02:00
|
|
|
|
2016-05-19 14:15:22 +02:00
|
|
|
|
|
|
|
if ((file->mode & 3)==FILE_OPEN_READ)
|
|
|
|
{
|
|
|
|
errno = E_ACCESS;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((file->mode &3)==FILE_OPEN_APPEND)
|
2006-09-07 16:14:53 +02:00
|
|
|
file->filepos=file->filesize;
|
2016-05-19 14:15:22 +02:00
|
|
|
|
|
|
|
fullsize=count*size;
|
|
|
|
|
2007-08-24 21:49:07 +02:00
|
|
|
if ((file->filesize)<(file->filepos+fullsize)) file->filesize=file->filepos+fullsize;
|
|
|
|
|
2007-10-15 11:42:17 +02:00
|
|
|
/*
|
|
|
|
if (file->mode==FILE_OPEN_APPEND)
|
2007-08-24 21:49:07 +02:00
|
|
|
{
|
|
|
|
file->filepos==file->filesize;
|
|
|
|
res=_ksys_appendtofile(file->filename,file->filepos,fullsize,buffer);
|
|
|
|
if (res==0)
|
|
|
|
{
|
|
|
|
file->filepos+=fullsize;
|
|
|
|
fullsize=fullsize/size;
|
|
|
|
return(fullsize);
|
|
|
|
}
|
|
|
|
else return(0);
|
2016-05-19 14:15:22 +02:00
|
|
|
|
2007-08-24 21:49:07 +02:00
|
|
|
}
|
2007-10-15 11:42:17 +02:00
|
|
|
*/
|
2018-03-12 21:41:06 +01:00
|
|
|
file->ungetc_buf = EOF;
|
|
|
|
if (file->filepos >= file->buffer_start && file->filepos < file->buffer_end) // drop buffer, if change his data
|
|
|
|
{
|
|
|
|
file->buffer_start = -1;
|
|
|
|
file->buffer_end = -1;
|
|
|
|
}
|
|
|
|
|
2016-05-19 14:15:22 +02:00
|
|
|
if ((file->mode &3)==FILE_OPEN_WRITE || (file->mode&3)==FILE_OPEN_APPEND) // always true, as read checked previous
|
2006-09-07 16:14:53 +02:00
|
|
|
{
|
2007-08-24 21:49:07 +02:00
|
|
|
if (file->filepos==0)
|
2016-05-19 14:15:22 +02:00
|
|
|
{ //file mot created yet
|
2007-08-24 21:49:07 +02:00
|
|
|
res=_ksys_rewritefile(file->filename,fullsize,buffer);
|
|
|
|
if (res==0)
|
|
|
|
{
|
|
|
|
file->filepos+=fullsize;
|
|
|
|
fullsize=fullsize/count;
|
|
|
|
return(fullsize);
|
2016-05-19 14:15:22 +02:00
|
|
|
} else
|
|
|
|
{
|
|
|
|
errno = -res;
|
|
|
|
return(0);
|
|
|
|
}
|
2007-08-24 21:49:07 +02:00
|
|
|
}
|
|
|
|
else
|
2016-05-19 14:15:22 +02:00
|
|
|
{
|
|
|
|
res=_ksys_appendtofile(file->filename,file->filepos,fullsize,buffer);
|
2007-08-24 21:49:07 +02:00
|
|
|
if (res==0)
|
|
|
|
{
|
|
|
|
file->filepos+=fullsize;
|
|
|
|
fullsize=fullsize/count;
|
|
|
|
return(fullsize);
|
2016-05-19 14:15:22 +02:00
|
|
|
} else
|
|
|
|
{
|
|
|
|
errno = -res;
|
|
|
|
return(0);
|
|
|
|
}
|
2007-08-24 21:49:07 +02:00
|
|
|
}
|
2006-09-07 16:14:53 +02:00
|
|
|
}
|
2007-08-24 21:49:07 +02:00
|
|
|
else return(0);
|
2016-05-19 14:15:22 +02:00
|
|
|
}
|