diff options
author | Juan Manuel Tomás <jtomas1815@gmail.com> | 2020-07-14 22:15:15 -0300 |
---|---|---|
committer | Juan Manuel Tomás <jtomas1815@gmail.com> | 2020-07-14 22:15:15 -0300 |
commit | 54b3fb7adb40e4e536e3a172f503be213d091607 (patch) | |
tree | c9e213b16454c0640a958de09e52537b720754da | |
parent | 842355c831404cc1aa3d9ac0918eed0c2d2a86fc (diff) | |
download | jet-54b3fb7adb40e4e536e3a172f503be213d091607.tar.gz jet-54b3fb7adb40e4e536e3a172f503be213d091607.zip |
Fix pages not linked to previous ones
-rw-r--r-- | buffer.cpp | 24 | ||||
-rw-r--r-- | test | 6 |
2 files changed, 24 insertions, 6 deletions
@@ -4,18 +4,30 @@ struct Buffer { 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; - int bytes_read = read(file, iter->elements, PAGE_SIZE); - iter->gap_start = bytes_read; - iter->element_count = bytes_read; - while (bytes_read == PAGE_SIZE) { + 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); - iter->gap_start = bytes_read; - iter->element_count = bytes_read; + } + if (iter->element_count == 0) { + delete iter; } close(file); } @@ -0,0 +1,6 @@ +asdfasd +asdfasd +asdfasd +asdfasd +asdfasd +asdfasd |