You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2024/08/08 09:19:50 UTC

(nuttx) 02/02: tmpfs: write end of file if open flag with O_APPEND

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit a3b94383ed6fb8df25f4e3df5dfa5cd47e9b9ec9
Author: Shoukui Zhang <zh...@xiaomi.com>
AuthorDate: Sun Apr 28 21:50:43 2024 +0800

    tmpfs: write end of file if open flag with O_APPEND
    
    Signed-off-by: Shoukui Zhang <zh...@xiaomi.com>
---
 fs/tmpfs/fs_tmpfs.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/fs/tmpfs/fs_tmpfs.c b/fs/tmpfs/fs_tmpfs.c
index e4f5e6b257..34f2233630 100644
--- a/fs/tmpfs/fs_tmpfs.c
+++ b/fs/tmpfs/fs_tmpfs.c
@@ -1605,7 +1605,15 @@ static ssize_t tmpfs_write(FAR struct file *filep, FAR const char *buffer,
 
   /* Handle attempts to write beyond the end of the file */
 
-  startpos = filep->f_pos;
+  if ((filep->f_oflags & O_APPEND) != 0)
+    {
+      startpos = tfo->tfo_size;
+    }
+  else
+    {
+      startpos = filep->f_pos;
+    }
+
   nwritten = buflen;
   endpos   = startpos + buflen;
 
@@ -1625,13 +1633,14 @@ static ssize_t tmpfs_write(FAR struct file *filep, FAR const char *buffer,
   if (tfo->tfo_data != NULL)
     {
       memcpy(&tfo->tfo_data[startpos], buffer, nwritten);
-      filep->f_pos += nwritten;
     }
   else
     {
       DEBUGASSERT(tfo->tfo_size == 0 && nwritten == 0);
     }
 
+  filep->f_pos = endpos;
+
   /* Release the lock on the file */
 
   tmpfs_unlock_file(tfo);