lib: c: io: implement standard FILE and DIR interfaces
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user