lib: c: io: implement standard FILE and DIR interfaces

This commit is contained in:
2026-03-25 20:21:12 +00:00
parent b975256cb9
commit 96784f611f
21 changed files with 599 additions and 0 deletions
+31
View File
@@ -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;
}