summaryrefslogtreecommitdiff
path: root/buffer.cpp
diff options
context:
space:
mode:
authorJuan Manuel Tomás <jtomas1815@gmail.com>2020-07-17 16:23:43 -0300
committerJuan Manuel Tomás <jtomas1815@gmail.com>2020-07-17 16:23:43 -0300
commitd608bef678fa97b3af910fa62598c55f33650825 (patch)
tree90f1b4029be89a3ed3c55593b9787371c8037a35 /buffer.cpp
parentc1d93b0bc5a2abcf5e7cadd17ef9db7f57a524fc (diff)
downloadjet-d608bef678fa97b3af910fa62598c55f33650825.tar.gz
jet-d608bef678fa97b3af910fa62598c55f33650825.zip
Restructure source files
Diffstat (limited to 'buffer.cpp')
-rw-r--r--buffer.cpp45
1 files changed, 0 insertions, 45 deletions
diff --git a/buffer.cpp b/buffer.cpp
deleted file mode 100644
index 7b4c92d..0000000
--- a/buffer.cpp
+++ /dev/null
@@ -1,45 +0,0 @@
-struct Buffer {
- const char *name;
- Page *storage;
-
- Buffer(const char *name) : name(name), storage(new Page()) {}
-
- void free_storage() {
- while (storage) {
- Page *iter = storage;
- storage = storage->next;
- delete iter;
- }
- }
-
- void read_file(const char *pathname) {
- free_storage();
- int file = open(pathname, O_RDONLY);
- storage = new Page();
- int bytes_read = read(file, storage->elements, PAGE_SIZE);
- Page *iter = storage;
- while (bytes_read > 0) {
- iter->gap_start = bytes_read;
- iter->element_count = bytes_read;
- iter->next = new Page();
- iter->next->prev = iter;
- iter = iter->next;
- bytes_read = read(file, iter->elements, PAGE_SIZE);
- }
- if (iter->element_count == 0) {
- delete iter;
- }
- close(file);
- }
-
- 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;
- }
- close(file);
- }
-};