summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Manuel Tomás <jtomas1815@gmail.com>2020-07-10 21:54:04 -0300
committerJuan Manuel Tomás <jtomas1815@gmail.com>2020-07-10 21:54:04 -0300
commitc4c5be557abb30166dbc49770a0151671ab1bf07 (patch)
treea642972e425533e91e3d46eb6fb71d2bc276f076
parent5c8326ae953eee1cd36711a7769cff624f312864 (diff)
downloadjet-c4c5be557abb30166dbc49770a0151671ab1bf07.tar.gz
jet-c4c5be557abb30166dbc49770a0151671ab1bf07.zip
Implement file writing using the write syscall
-rw-r--r--buffer.cpp13
-rw-r--r--jet.cpp2
2 files changed, 9 insertions, 6 deletions
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);
}
};
diff --git a/jet.cpp b/jet.cpp
index 1a2e9c9..3d45c75 100644
--- a/jet.cpp
+++ b/jet.cpp
@@ -64,7 +64,7 @@ int main() {
epoll_event events[MAX_EVENTS];
Client *clients[1024] = {};
- for (;;) {
+ while (true) {
int nfds = epoll_wait(epollfd, events, MAX_EVENTS, -1);
for (int i = 0; i < nfds; i++) {