From c4c5be557abb30166dbc49770a0151671ab1bf07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Fri, 10 Jul 2020 21:54:04 -0300 Subject: Implement file writing using the write syscall --- buffer.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'buffer.cpp') diff --git a/buffer.cpp b/buffer.cpp index ff5ae60..ba3f87c 100644 --- a/buffer.cpp +++ b/buffer.cpp @@ -20,11 +20,14 @@ struct Buffer { close(file); } - void write_file(const char *file) { - FILE *f = fopen(file, "w+"); - for (Point p(storage, 0); !p.at_end(); p++) { - fputc(p.element(), f); + void write_file(const char *pathname) { + int file = open(pathname, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + Page *iter = storage; + while (iter) { + write(file, iter->elements, iter->gap_start); + write(file, iter->elements + iter->gap_end, PAGE_SIZE - iter->gap_end); + iter = iter->next; } - fclose(f); + close(file); } }; -- cgit v1.2.3