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
+40
View File
@@ -0,0 +1,40 @@
#include "file.h"
#include <stdio.h>
char *fgets(
char *restrict str,
int count,
struct __opaque_file *restrict stream)
{
if (stream->f_flags & (FILE_EOF | FILE_ERR)) {
return NULL;
}
size_t i = 0;
while (1) {
int c = fgetc(stream);
if (c == EOF) {
str[i] = 0;
break;
}
str[i++] = c;
if (c == '\n') {
str[i] = 0;
break;
}
}
if (ferr(stream)) {
return NULL;
}
if (feof(stream) && i == 0) {
return NULL;
}
return str;
}