tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[PATCH] rfc: write() shifts offset if number of bytes to write is zero



write() changes offset of the file even if number of bytes to write equal to
zero.
---
 sys/kern/vfs_vnops.c |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c
index 6bd5c11..c564ed7 100644
--- a/sys/kern/vfs_vnops.c
+++ b/sys/kern/vfs_vnops.c
@@ -491,9 +491,17 @@ vn_write(file_t *fp, off_t *offset, struct uio *uio, 
kauth_cred_t cred,
        count = uio->uio_resid;
        error = VOP_WRITE(vp, uio, ioflag, cred);
        if (flags & FOF_UPDATE_OFFSET) {
-               if (ioflag & IO_APPEND)
-                       *offset = uio->uio_offset;
-               else
+               if (ioflag & IO_APPEND) {
+                       /*
+                        * SUSv3 describes behaviour for count = 0 as following:
+                        * "Before any action ... is taken, and if nbyte is zero
+                        * and the file is a regular file, the write() function
+                        * ... in the absence of errors ... shall return zero
+                        * and have no other results."
+                        */ 
+                       if (count)
+                               *offset = uio->uio_offset;
+               } else
                        *offset += count - uio->uio_resid;
        }
        VOP_UNLOCK(vp, 0);
-- 
1.5.2.5



Home | Main Index | Thread Index | Old Index