meta: move photon/libc to root
This commit is contained in:
49
libc/sys/linux/fio.c
Normal file
49
libc/sys/linux/fio.c
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user