summaryrefslogtreecommitdiff
path: root/Kernel/Process.cpp
diff options
context:
space:
mode:
authorRobin Burchell <robin+git@viroteck.net>2019-05-26 01:18:04 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-05-26 01:32:05 +0200
commitc6e79bd53a37aa0d9fb7c610d7d251a9e1b0a11d (patch)
treee77ed0234988035b4f1df9038cf190c94d6b4cdd /Kernel/Process.cpp
parent90dbf689c006f3335aaec1129d01f1f921e2122c (diff)
downloadserenity-c6e79bd53a37aa0d9fb7c610d7d251a9e1b0a11d.zip
Kernel: Support O_APPEND
As per the manpage, this acts as a transparent lseek() before write.
Diffstat (limited to 'Kernel/Process.cpp')
-rw-r--r--Kernel/Process.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp
index d8962144a5..4725c3bf52 100644
--- a/Kernel/Process.cpp
+++ b/Kernel/Process.cpp
@@ -861,6 +861,13 @@ ssize_t Process::do_write(FileDescriptor& descriptor, const byte* data, int data
return -EAGAIN;
}
+ if (descriptor.should_append()) {
+#ifdef IO_DEBUG
+ dbgprintf("seeking to end (O_APPEND)\n");
+#endif
+ descriptor.seek(0, SEEK_END);
+ }
+
while (nwritten < data_size) {
#ifdef IO_DEBUG
dbgprintf("while %u < %u\n", nwritten, size);
@@ -1118,8 +1125,8 @@ int Process::sys$open(const char* path, int options, mode_t mode)
auto descriptor = result.value();
if (options & O_DIRECTORY && !descriptor->is_directory())
return -ENOTDIR; // FIXME: This should be handled by VFS::open.
- if (options & O_NONBLOCK)
- descriptor->set_blocking(false);
+ descriptor->set_blocking(!(options & O_NONBLOCK));
+ descriptor->set_should_append(options & O_APPEND);
dword flags = (options & O_CLOEXEC) ? FD_CLOEXEC : 0;
m_fds[fd].set(move(descriptor), flags);
return fd;