kolibrios/programs/develop/ktcc/trunk/libc/stdio/fputc.c
siemargl ace23ebbe2 libc testsuite + fixes
git-svn-id: svn://kolibrios.org@6433 a494cfbc-eb01-0410-851d-a64ba20cac60
2016-05-19 12:15:22 +00:00

57 lines
1.1 KiB
C

#include <stdio.h>
int fputc(int c,FILE* file)
{
dword res;
if(!file)
{
errno = E_INVALIDPTR;
return EOF;
}
if ((file->mode & 3)==FILE_OPEN_READ)
{
errno = E_ACCESS;
return EOF;
}
file->buffer[0]=c;
if ((file->mode & 3)==FILE_OPEN_APPEND)
{
file->filepos=file->filesize;
file->filesize++;
res=_ksys_appendtofile(file->filename,file->filepos,1,file->buffer);
if (res!=0)
{
errno = -res;
return EOF;
}
file->filepos++;
return c;
}
if ((file->mode & 3)==FILE_OPEN_WRITE)
{
if (file->filepos==0)
{ //file not created
res=_ksys_rewritefile(file->filename,1,file->buffer);
if (res!=0)
{
errno = -res;
return EOF;
}
file->filepos++;
return c;
}
else
{ //file created and need append one byte
res=_ksys_appendtofile(file->filename,file->filepos,1,file->buffer);
if (res!=0)
{
errno = -res;
return EOF;
}
file->filepos++;
return c;
}
}
}