fs/vfs: ftruncate produce EINVAL if fd is not open for writing

As posix spec, ftruncate should produce EBADF or EINVAL error,
if the file descriptor fd is not open for writing.

Change the behavior to be similar to Linux and pass ltp open_posix test:
testcases/open_posix_testsuite/conformance/interfaces/shm_open/20-1.c

https://pubs.opengroup.org/onlinepubs/9699919799/functions/ftruncate.html
https://man7.org/linux/man-pages/man2/ftruncate.2.html

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
This commit is contained in:
fangxinyong 2023-06-09 21:13:21 +08:00 committed by Xiang Xiao
parent 44442a655e
commit 5176fb917a
1 changed files with 1 additions and 1 deletions

View File

@ -57,7 +57,7 @@ int file_truncate(FAR struct file *filep, off_t length)
if ((filep->f_oflags & O_WROK) == 0)
{
fwarn("WARNING: Cannot truncate a file opened read-only\n");
return -EBADF;
return -EINVAL;
}
/* Is this inode a registered mountpoint? Does it support the