meta: move photon/libc to root

This commit is contained in:
2026-02-08 20:45:25 +00:00
parent f00e74260d
commit 345a37962e
140 changed files with 0 additions and 0 deletions

49
libc/sys/linux/fio.c Normal file
View File

@@ -0,0 +1,49 @@
#include "__fio.h"
#include "__syscall.h"
#include "unistd.h"
struct __io_file __stdin = { .fd = 0 };
struct __io_file __stdout = { .fd = 1 };
struct __io_file __stderr = { .fd = 2 };
struct __io_file *stdin = &__stdin;
struct __io_file *stdout = &__stdout;
struct __io_file *stderr = &__stderr;
int __fileno(struct __io_file *f)
{
return f->fd;
}
unsigned int __fio_write(struct __io_file *f, const char *buf, unsigned int sz)
{
for (unsigned int i = 0; i < sz; i++) {
if (f->buf_idx >= __FIO_BUFSZ) {
__fio_flush(f);
}
f->buf[f->buf_idx++] = buf[i];
if (buf[i] == '\n') {
__fio_flush(f);
}
}
return sz;
}
unsigned int __fio_flush(struct __io_file *f)
{
ssize_t res = write(f->fd, f->buf, f->buf_idx);
if (res != f->buf_idx) {
f->err = 1;
}
size_t flushed = f->buf_idx;
f->buf_idx = 0;
return flushed;
}
int __fio_error(struct __io_file *f)
{
return f->err != 0;
}