lib: posix: fs: add ftruncate support

Add support for ftruncate in posix implementation

Signed-off-by: Karthikeyan Krishnasamy <karthikeyan@linumiz.com>
This commit is contained in:
Karthikeyan Krishnasamy 2024-04-13 13:14:31 +05:30 committed by Chris Friedt
parent feae0a229b
commit cd1ed1cdbf
2 changed files with 16 additions and 0 deletions

View File

@ -238,6 +238,7 @@ ssize_t write(int file, const void *buffer, size_t count);
ssize_t read(int file, void *buffer, size_t count);
off_t lseek(int file, off_t offset, int whence);
int fsync(int fd);
int ftruncate(int fd, off_t length);
/* File System related operations */
int rename(const char *old, const char *newp);

View File

@ -416,3 +416,18 @@ int mkdir(const char *path, mode_t mode)
return 0;
}
/**
* @brief Truncate file to specified length.
*
*/
int ftruncate(int fd, off_t length)
{
struct posix_fs_desc *ptr = NULL;
ptr = z_get_fd_obj(fd, NULL, EBADF);
if (!ptr)
return -1;
return fs_truncate(&ptr->file, length);
}