2021-03-02 18:58:11 +01:00
|
|
|
#include <stdio.h>
|
2021-03-02 19:57:57 +01:00
|
|
|
#include <errno.h>
|
|
|
|
#include <ksys.h>
|
2021-03-02 18:58:11 +01:00
|
|
|
|
|
|
|
int fgetc(FILE* stream)
|
|
|
|
{
|
2021-03-02 19:57:57 +01:00
|
|
|
unsigned bytes_read;
|
|
|
|
char c;
|
|
|
|
|
|
|
|
unsigned status = _ksys_file_read_file(stream->name, stream->position, 1, &c, &bytes_read);
|
|
|
|
|
2021-03-02 22:28:51 +01:00
|
|
|
if (status != KSYS_FS_ERR_SUCCESS) {
|
2021-03-02 19:57:57 +01:00
|
|
|
switch (status) {
|
2021-03-02 22:28:51 +01:00
|
|
|
case KSYS_FS_ERR_EOF:
|
2021-03-02 19:57:57 +01:00
|
|
|
stream->eof = 1;
|
|
|
|
break;
|
2021-03-02 22:28:51 +01:00
|
|
|
case KSYS_FS_ERR_1:
|
|
|
|
case KSYS_FS_ERR_2:
|
|
|
|
case KSYS_FS_ERR_3:
|
|
|
|
case KSYS_FS_ERR_4:
|
|
|
|
case KSYS_FS_ERR_5:
|
|
|
|
case KSYS_FS_ERR_7:
|
|
|
|
case KSYS_FS_ERR_8:
|
|
|
|
case KSYS_FS_ERR_9:
|
|
|
|
case KSYS_FS_ERR_10:
|
|
|
|
case KSYS_FS_ERR_11:
|
2021-03-02 19:57:57 +01:00
|
|
|
default:
|
|
|
|
// Just some IO error, who knows what exactly happened
|
|
|
|
errno = EIO;
|
|
|
|
stream->error = errno;
|
|
|
|
break;
|
|
|
|
}
|
2021-03-02 18:58:11 +01:00
|
|
|
return EOF;
|
|
|
|
}
|
2021-03-02 19:57:57 +01:00
|
|
|
|
|
|
|
stream->position++;
|
2021-03-02 18:58:11 +01:00
|
|
|
return c;
|
|
|
|
}
|