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 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
dongjiuzhu1 2024-10-31 20:57:45 +08:00 committed by Alan C. Assis
parent d1e5b38b9b
commit 47478e543d
1 changed files with 11 additions and 0 deletions

View File

@ -108,6 +108,17 @@ static int file_shm_open(FAR struct file *shm, FAR const char *name,
inode_release(inode); inode_release(inode);
goto errout_with_sem; 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 else
{ {