libc: io: implement file io buffering and internal locking for concurrency

This commit is contained in:
2026-04-01 18:51:13 +01:00
parent f2e650d368
commit 548387c43a
23 changed files with 948 additions and 73 deletions
+31
View File
@@ -0,0 +1,31 @@
#include "file.h"
#include <stdio.h>
extern int __fputc(int c, struct __opaque_file *stream);
int fputs(const char *restrict str, struct __opaque_file *restrict stream)
{
__libc_file_lock(stream);
if (stream->f_flags & (FILE_EOF | FILE_ERR)) {
__libc_file_unlock(stream);
return EOF;
}
size_t i = 0;
int err = 0;
for (i = 0; str[i]; i++) {
err = __fputc(str[i], stream);
if (err < 0) {
break;
}
}
__libc_file_unlock(stream);
if (i > 0) {
return i;
}
return err;
}