This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 47478e543d fs/shm: support shm_open with flags O_TRUNC
47478e543d is described below
commit 47478e543dbe3fa9391035137e501c6739d4c872
Author: dongjiuzhu1 <[email protected]>
AuthorDate: Thu Oct 31 20:57:45 2024 +0800
fs/shm: support shm_open with flags O_TRUNC
testcase:
https://fossies.org/linux/posixtestsuite/conformance/interfaces/shm_open/25-1.c
Signed-off-by: dongjiuzhu1 <[email protected]>
---
fs/shm/shm_open.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/fs/shm/shm_open.c b/fs/shm/shm_open.c
index 431ba2e0b7..50dacd5201 100644
--- a/fs/shm/shm_open.c
+++ b/fs/shm/shm_open.c
@@ -108,6 +108,17 @@ static int file_shm_open(FAR struct file *shm, FAR const
char *name,
inode_release(inode);
goto errout_with_sem;
}
+
+ /* If the shared memory object already exists, truncate it to
+ * zero bytes.
+ */
+
+ if ((oflags & O_TRUNC) == O_TRUNC && inode->i_private != NULL)
+ {
+ shmfs_free_object(inode->i_private);
+ inode->i_private = NULL;
+ inode->i_size = 0;
+ }
}
else
{