Files
rosetta/lib/libc/io/stdio/fgetc.c
T

32 lines
561 B
C
Raw Normal View History

#include "file.h"
#include <errno.h>
#include <stdio.h>
int fgetc(struct __opaque_file *stream)
{
if (stream->f_flags & (FILE_EOF | FILE_ERR)) {
return EOF;
}
size_t available = __libc_file_available(stream);
if (available == 0) {
int err = __libc_file_refill(stream);
if (err != SUCCESS) {
__set_errno(err);
stream->f_flags |= FILE_ERR;
return EOF;
}
available = __libc_file_available(stream);
}
if (available == 0) {
stream->f_flags |= FILE_EOF;
return EOF;
}
char c = stream->f_buf[stream->f_buf_readptr++];
return c;
}