Implemented fio_read, fio_write, and fio_flush on Horizon
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
#include <magenta/misc.h>
|
#include <magenta/misc.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include "sys/types.h"
|
#include "sys/types.h"
|
||||||
#include "__fio.h"
|
#include "__fio.h"
|
||||||
|
|
||||||
@@ -55,12 +56,28 @@ int __fileno(struct __io_file *f)
|
|||||||
|
|
||||||
unsigned int __fio_read(struct __io_file *f, char *buf, unsigned int sz)
|
unsigned int __fio_read(struct __io_file *f, char *buf, unsigned int sz)
|
||||||
{
|
{
|
||||||
|
ssize_t err = read(f->fd, buf, sz);
|
||||||
|
if (err < 0) {
|
||||||
|
f->err = 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int __fio_write(struct __io_file *f, const char *buf, unsigned int sz)
|
unsigned int __fio_write(struct __io_file *f, const char *buf, unsigned int sz)
|
||||||
{
|
{
|
||||||
mx_console_write(buf, 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;
|
return sz;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,7 +88,14 @@ int __fio_ungetc(struct __io_file *f, char c)
|
|||||||
|
|
||||||
unsigned int __fio_flush(struct __io_file *f)
|
unsigned int __fio_flush(struct __io_file *f)
|
||||||
{
|
{
|
||||||
return 0;
|
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)
|
int __fio_error(struct __io_file *f)
|
||||||
|
|||||||
Reference in New Issue
Block a user