lib: posix: fs: fix errno handling
ftruncate should return -1 on errors and it needs to set appropriate error values in errno Signed-off-by: Karthikeyan Krishnasamy <karthikeyan@linumiz.com>
This commit is contained in:
parent
191b3cbe10
commit
cc06c2b21f
1 changed files with 8 additions and 1 deletions
|
@ -423,11 +423,18 @@ int mkdir(const char *path, mode_t mode)
|
|||
*/
|
||||
int ftruncate(int fd, off_t length)
|
||||
{
|
||||
int rc;
|
||||
struct posix_fs_desc *ptr = NULL;
|
||||
|
||||
ptr = z_get_fd_obj(fd, NULL, EBADF);
|
||||
if (!ptr)
|
||||
return -1;
|
||||
|
||||
return fs_truncate(&ptr->file, length);
|
||||
rc = fs_truncate(&ptr->file, length);
|
||||
if (rc < 0) {
|
||||
errno = -rc;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue