kolibrios/contrib/kolibri-libc/source/stdio/fputc.c
Magomed Kostoev (mkostoevr) 162d919194 kolibri-libc: Reimplement fgets, fputc, fputs, fread and fwrite
Now it follows the POSIX specification better.

git-svn-id: svn://kolibrios.org@8624 a494cfbc-eb01-0410-851d-a64ba20cac60
2021-03-02 18:57:57 +00:00

35 lines
897 B
C

#include <stdio.h>
#include <errno.h>
#include <ksys.h>
int fputc(int c, FILE *stream)
{
unsigned bytes_written;
unsigned status = _ksys_file_write_file(stream->name, stream->position, 1, &c, &bytes_written);
if (status != _KOS_FS_ERR_SUCCESS) {
switch (status) {
case _KOS_FS_ERR_1:
case _KOS_FS_ERR_2:
case _KOS_FS_ERR_3:
case _KOS_FS_ERR_4:
case _KOS_FS_ERR_5:
case _KOS_FS_ERR_EOF:
case _KOS_FS_ERR_7:
case _KOS_FS_ERR_8:
case _KOS_FS_ERR_9:
case _KOS_FS_ERR_10:
case _KOS_FS_ERR_11:
default:
// Just some IO error, who knows what exactly happened
errno = EIO;
stream->error = errno;
break;
}
return EOF;
}
stream->position++;
return c;
}