From a3b94383ed6fb8df25f4e3df5dfa5cd47e9b9ec9 Mon Sep 17 00:00:00 2001 From: Shoukui Zhang Date: Sun, 28 Apr 2024 21:50:43 +0800 Subject: [PATCH] tmpfs: write end of file if open flag with O_APPEND Signed-off-by: Shoukui Zhang --- 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);