Magenta is becoming a microkernel, so all these file IO functions are now deprecated

This commit is contained in:
Max Wash
2020-08-29 20:08:08 +01:00
parent ed2529835c
commit 6a04b05bad

View File

@@ -50,32 +50,17 @@ void __fio_init(mx_handle_t in, mx_handle_t out, mx_handle_t err)
int __fio_fopen(const char *path, const char *mode, struct __io_file *fp)
{
mx_handle_t h = MX_NULL_HANDLE;
mx_flags_t flags = flags_from_mode(mode);
mx_status_t stat = mx_file_open(MX_NULL_HANDLE, path, flags, &h);
if (stat != MX_OK) {
return -1;
}
fp->handle = h;
return 0;
return -1;
}
int __fio_fclose(struct __io_file *fp)
{
if (mx_handle_close(fp->handle) != MX_OK) {
return -1;
}
return 0;
return -1;
}
int __fio_fdopen(mx_handle_t fd, const char *mode, struct __io_file *fp)
{
/* TODO validate handle and mode */
fp->handle = fd;
return 0;
return -1;
}
int __fileno(struct __io_file *f)
@@ -85,69 +70,22 @@ int __fileno(struct __io_file *f)
unsigned int __fio_read(struct __io_file *f, char *buf, unsigned int sz)
{
if (!sz) {
return 0;
}
size_t i = 0;
unsigned long real_sz = 0;
if (f->unget) {
buf[i++] = f->unget;
f->unget = 0;
sz--;
}
if (!sz) {
return real_sz;
}
mx_status_t err = mx_object_read(f->handle, sz, buf + i, &real_sz);
if (err != MX_OK || real_sz != sz) {
f->err = 1;
}
return real_sz + i;
return 0;
}
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;
return 0;
}
int __fio_ungetc(struct __io_file *f, char c)
{
if (f->unget) {
return -1;
}
f->unget = c;
return 0;
}
unsigned int __fio_flush(struct __io_file *f)
{
unsigned long written = 0;
mx_status_t ret = mx_object_write(f->handle, f->buf_idx, f->buf, &written);
if (ret != MX_OK || written != f->buf_idx) {
f->err = 1;
}
size_t flushed = f->buf_idx;
f->buf_idx = 0;
return flushed;
return 0;
}
int __fio_error(struct __io_file *f)