From 973fdae9d84f6039effea431eb6fb9343a9a0ad2 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Fri, 29 Mar 2013 22:42:15 +0100 Subject: [PATCH] libc_fs: Fix seek report for ro (non-append) files --- libports/src/lib/libc_fs/plugin.cc | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/libports/src/lib/libc_fs/plugin.cc b/libports/src/lib/libc_fs/plugin.cc index 4f24e03f22..f19cd2267c 100644 --- a/libports/src/lib/libc_fs/plugin.cc +++ b/libports/src/lib/libc_fs/plugin.cc @@ -526,11 +526,25 @@ class Plugin : public Libc::Plugin Plugin_context *context = new (Genode::env()->heap()) Plugin_context(handle); + /* + * Prevent returning the file size as current seek offset + * for files that are opened read only because this + * behaviour is only useful for appending write operations + * to files. + * + * XXX Improve handling of files opened in append mode. + */ + if ((flags & O_ACCMODE) == O_RDONLY) + context->seek_offset(0); + context->status_flags(flags); Libc::File_descriptor *fd = Libc::file_descriptor_allocator()->alloc(this, context); - if ((flags & O_TRUNC) && (ftruncate(fd, 0) == -1)) + if ((flags & O_TRUNC) && (ftruncate(fd, 0) == -1)) { + Libc::file_descriptor_allocator()->free(fd); + destroy(Genode::env()->heap(), context); return 0; + } return fd; } catch (File_system::Lookup_failed) {